~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to doc/orm/events.html

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Jakub Wilk, Piotr Ożarowski
  • Date: 2013-07-06 20:53:52 UTC
  • mfrom: (1.4.23) (16.1.17 experimental)
  • Revision ID: package-import@ubuntu.com-20130706205352-ryppl1eto3illd79
Tags: 0.8.2-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Piotr Ożarowski ]
* New upstream release
* Upload to unstable
* Build depend on python3-all instead of -dev, extensions are not built for
  Python 3.X 

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
    
11
11
                ORM Events
12
12
             — 
13
 
    SQLAlchemy 0.7 Documentation
 
13
    SQLAlchemy 0.8 Documentation
14
14
 
15
15
        </title>
16
16
        
20
20
    <script type="text/javascript">
21
21
      var DOCUMENTATION_OPTIONS = {
22
22
          URL_ROOT:    '../',
23
 
          VERSION:     '0.7.9',
 
23
          VERSION:     '0.8.2',
24
24
          COLLAPSE_MODINDEX: false,
25
25
          FILE_SUFFIX: '.html'
26
26
      };
32
32
    <link rel="index" title="Index" href="../genindex.html" />
33
33
    <link rel="search" title="Search" href="../search.html" />
34
34
        <link rel="copyright" title="Copyright" href="../copyright.html" />
35
 
    <link rel="top" title="SQLAlchemy 0.7 Documentation" href="../index.html" />
 
35
    <link rel="top" title="SQLAlchemy 0.8 Documentation" href="../index.html" />
36
36
        <link rel="up" title="SQLAlchemy ORM" href="index.html" />
37
37
        <link rel="next" title="ORM Extensions" href="extensions/index.html" />
38
38
        <link rel="prev" title="Relationship Loading Techniques" href="loading.html" />
55
55
 
56
56
 
57
57
<div id="docs-header">
58
 
    <h1>SQLAlchemy 0.7 Documentation</h1>
 
58
    <h1>SQLAlchemy 0.8 Documentation</h1>
59
59
 
60
60
    <div id="docs-search">
61
61
    Search:
67
67
    </div>
68
68
 
69
69
    <div id="docs-version-header">
70
 
        Release: <span class="version-num">0.7.9</span> | Release Date: October 1, 2012
 
70
        Release: <span class="version-num">0.8.2</span> | Release Date: July 3, 2013
71
71
 
72
72
 
73
73
    </div>
93
93
    </div>
94
94
 
95
95
    <div id="docs-navigation-banner">
96
 
        <a href="../index.html">SQLAlchemy 0.7 Documentation</a>
 
96
        <a href="../index.html">SQLAlchemy 0.8 Documentation</a>
97
97
                » <a href="index.html" title="SQLAlchemy ORM">SQLAlchemy ORM</a>
98
98
        » 
99
99
                ORM Events
119
119
<li><a class="reference internal" href="#instance-events">Instance Events</a></li>
120
120
<li><a class="reference internal" href="#session-events">Session Events</a></li>
121
121
<li><a class="reference internal" href="#instrumentation-events">Instrumentation Events</a></li>
122
 
<li><a class="reference internal" href="#alternate-class-instrumentation">Alternate Class Instrumentation</a></li>
123
122
</ul>
124
123
</li>
125
124
</ul>
327
326
 
328
327
<span class="c"># associate the listener function with SomeMappedClass,</span>
329
328
<span class="c"># to execute during the &quot;before_insert&quot; hook</span>
330
 
<span class="n">event</span><span class="o">.</span><span class="n">listen</span><span class="p">(</span><span class="n">SomeMappedClass</span><span class="p">,</span> <span class="s">&#39;before_insert&#39;</span><span class="p">,</span> <span class="n">my_before_insert_listener</span><span class="p">)</span></pre></div>
 
329
<span class="n">event</span><span class="o">.</span><span class="n">listen</span><span class="p">(</span>
 
330
    <span class="n">SomeMappedClass</span><span class="p">,</span> <span class="s">&#39;before_insert&#39;</span><span class="p">,</span> <span class="n">my_before_insert_listener</span><span class="p">)</span></pre></div>
331
331
</div>
332
332
<p>Available targets include mapped classes, instances of
333
333
<a class="reference internal" href="mapper_config.html#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> (i.e. returned by <a class="reference internal" href="mapper_config.html#sqlalchemy.orm.mapper" title="sqlalchemy.orm.mapper"><tt class="xref py py-func docutils literal"><span class="pre">mapper()</span></tt></a>,
362
362
<tbody valign="top">
363
363
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
364
364
<li><strong>propagate=False</strong> &#8211; When True, the event listener should
365
 
be applied to all inheriting mappers as well as the
 
365
be applied to all inheriting mappers and/or the mappers of
 
366
inheriting classes, as well as any
366
367
mapper which is the target of this listener.</li>
367
368
<li><strong>raw=False</strong> &#8211; When True, the &#8220;target&#8221; argument passed
368
369
to applicable event listener functions will be the
397
398
used.</p>
398
399
<p>Theoretically this event is called once per
399
400
application, but is actually called any time new mappers
400
 
have been affected by a <a class="reference internal" href="mapper_config.html#sqlalchemy.orm.configure_mappers" title="sqlalchemy.orm.configure_mappers"><tt class="xref py py-func docutils literal"><span class="pre">orm.configure_mappers()</span></tt></a> call.   If new mappings
401
 
are constructed after existing ones have already been used,
402
 
this event can be called again.</p>
 
401
have been affected by a <a class="reference internal" href="mapper_config.html#sqlalchemy.orm.configure_mappers" title="sqlalchemy.orm.configure_mappers"><tt class="xref py py-func docutils literal"><span class="pre">orm.configure_mappers()</span></tt></a>
 
402
call.   If new mappings are constructed after existing ones have
 
403
already been used, this event can be called again.</p>
403
404
</dd></dl>
404
405
 
405
406
<dl class="method">
417
418
<p class="first admonition-title">Warning</p>
418
419
<p>Mapper-level flush events are designed to operate <strong>on attributes
419
420
local to the immediate object being handled
420
 
and via SQL operations with the given</strong> <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> <strong>only.</strong>
421
 
Handlers here should <strong>not</strong> make alterations to the state of
422
 
the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> overall, and in general should not
 
421
and via SQL operations with the given</strong> <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a>
 
422
<strong>only.</strong> Handlers here should <strong>not</strong> make alterations to the
 
423
state of the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> overall, and in general should not
423
424
affect any <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> -mapped attributes, as
424
425
session cascade rules will not function properly, nor is it
425
426
always known if the related class has already been handled.
428
429
<li><a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.add" title="sqlalchemy.orm.session.Session.add"><tt class="xref py py-meth docutils literal"><span class="pre">Session.add()</span></tt></a></li>
429
430
<li><a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.delete" title="sqlalchemy.orm.session.Session.delete"><tt class="xref py py-meth docutils literal"><span class="pre">Session.delete()</span></tt></a></li>
430
431
<li>Mapped collection append, add, remove, delete, discard, etc.</li>
431
 
<li>Mapped relationship attribute set/del events, i.e. <tt class="docutils literal"><span class="pre">someobject.related</span> <span class="pre">=</span> <span class="pre">someotherobject</span></tt></li>
 
432
<li>Mapped relationship attribute set/del events,
 
433
i.e. <tt class="docutils literal"><span class="pre">someobject.related</span> <span class="pre">=</span> <span class="pre">someotherobject</span></tt></li>
432
434
</ul>
433
435
<p>Operations which manipulate the state of the object
434
436
relative to other objects are better handled:</p>
435
437
<ul class="last simple">
436
 
<li>In the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the mapped object itself, or another method
437
 
designed to establish some particular state.</li>
 
438
<li>In the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the mapped object itself,
 
439
or another method designed to establish some particular state.</li>
438
440
<li>In a <tt class="docutils literal"><span class="pre">&#64;validates</span></tt> handler, see <a class="reference internal" href="mapper_config.html#simple-validators"><em>Simple Validators</em></a></li>
439
441
<li>Within the  <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_flush" title="sqlalchemy.orm.events.SessionEvents.before_flush"><tt class="xref py py-meth docutils literal"><span class="pre">SessionEvents.before_flush()</span></tt></a> event.</li>
440
442
</ul>
446
448
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
447
449
<li><strong>mapper</strong> &#8211; the <a class="reference internal" href="mapper_config.html#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> which is the target
448
450
of this event.</li>
449
 
<li><strong>connection</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> being used to
 
451
<li><strong>connection</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> being used to
450
452
emit DELETE statements for this instance.  This
451
453
provides a handle into the current transaction on the
452
454
target database specific to this instance.</li>
485
487
<p class="first admonition-title">Warning</p>
486
488
<p>Mapper-level flush events are designed to operate <strong>on attributes
487
489
local to the immediate object being handled
488
 
and via SQL operations with the given</strong> <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> <strong>only.</strong>
489
 
Handlers here should <strong>not</strong> make alterations to the state of
490
 
the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> overall, and in general should not
491
 
affect any <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> -mapped attributes, as
492
 
session cascade rules will not function properly, nor is it
493
 
always known if the related class has already been handled.
494
 
Operations that <strong>are not supported in mapper events</strong> include:</p>
 
490
and via SQL operations with the given</strong>
 
491
<a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> <strong>only.</strong> Handlers here should <strong>not</strong> make
 
492
alterations to the state of the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> overall, and in
 
493
general should not affect any <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> -mapped
 
494
attributes, as session cascade rules will not function properly,
 
495
nor is it always known if the related class has already been
 
496
handled. Operations that <strong>are not supported in mapper
 
497
events</strong> include:</p>
495
498
<ul class="simple">
496
499
<li><a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.add" title="sqlalchemy.orm.session.Session.add"><tt class="xref py py-meth docutils literal"><span class="pre">Session.add()</span></tt></a></li>
497
500
<li><a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.delete" title="sqlalchemy.orm.session.Session.delete"><tt class="xref py py-meth docutils literal"><span class="pre">Session.delete()</span></tt></a></li>
498
501
<li>Mapped collection append, add, remove, delete, discard, etc.</li>
499
 
<li>Mapped relationship attribute set/del events, i.e. <tt class="docutils literal"><span class="pre">someobject.related</span> <span class="pre">=</span> <span class="pre">someotherobject</span></tt></li>
 
502
<li>Mapped relationship attribute set/del events,
 
503
i.e. <tt class="docutils literal"><span class="pre">someobject.related</span> <span class="pre">=</span> <span class="pre">someotherobject</span></tt></li>
500
504
</ul>
501
505
<p>Operations which manipulate the state of the object
502
506
relative to other objects are better handled:</p>
503
507
<ul class="last simple">
504
 
<li>In the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the mapped object itself, or another method
505
 
designed to establish some particular state.</li>
 
508
<li>In the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the mapped object itself,
 
509
or another method designed to establish some particular state.</li>
506
510
<li>In a <tt class="docutils literal"><span class="pre">&#64;validates</span></tt> handler, see <a class="reference internal" href="mapper_config.html#simple-validators"><em>Simple Validators</em></a></li>
507
511
<li>Within the  <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_flush" title="sqlalchemy.orm.events.SessionEvents.before_flush"><tt class="xref py py-meth docutils literal"><span class="pre">SessionEvents.before_flush()</span></tt></a> event.</li>
508
512
</ul>
514
518
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
515
519
<li><strong>mapper</strong> &#8211; the <a class="reference internal" href="mapper_config.html#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> which is the target
516
520
of this event.</li>
517
 
<li><strong>connection</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> being used to
 
521
<li><strong>connection</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> being used to
518
522
emit INSERT statements for this instance.  This
519
523
provides a handle into the current transaction on the
520
524
target database specific to this instance.</li>
569
573
<p class="first admonition-title">Warning</p>
570
574
<p>Mapper-level flush events are designed to operate <strong>on attributes
571
575
local to the immediate object being handled
572
 
and via SQL operations with the given</strong> <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> <strong>only.</strong>
573
 
Handlers here should <strong>not</strong> make alterations to the state of
574
 
the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> overall, and in general should not
 
576
and via SQL operations with the given</strong> <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a>
 
577
<strong>only.</strong> Handlers here should <strong>not</strong> make alterations to the
 
578
state of the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> overall, and in general should not
575
579
affect any <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> -mapped attributes, as
576
580
session cascade rules will not function properly, nor is it
577
581
always known if the related class has already been handled.
580
584
<li><a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.add" title="sqlalchemy.orm.session.Session.add"><tt class="xref py py-meth docutils literal"><span class="pre">Session.add()</span></tt></a></li>
581
585
<li><a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.delete" title="sqlalchemy.orm.session.Session.delete"><tt class="xref py py-meth docutils literal"><span class="pre">Session.delete()</span></tt></a></li>
582
586
<li>Mapped collection append, add, remove, delete, discard, etc.</li>
583
 
<li>Mapped relationship attribute set/del events, i.e. <tt class="docutils literal"><span class="pre">someobject.related</span> <span class="pre">=</span> <span class="pre">someotherobject</span></tt></li>
 
587
<li>Mapped relationship attribute set/del events,
 
588
i.e. <tt class="docutils literal"><span class="pre">someobject.related</span> <span class="pre">=</span> <span class="pre">someotherobject</span></tt></li>
584
589
</ul>
585
590
<p>Operations which manipulate the state of the object
586
591
relative to other objects are better handled:</p>
587
592
<ul class="last simple">
588
 
<li>In the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the mapped object itself, or another method
589
 
designed to establish some particular state.</li>
 
593
<li>In the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the mapped object itself,
 
594
or another method designed to establish some particular state.</li>
590
595
<li>In a <tt class="docutils literal"><span class="pre">&#64;validates</span></tt> handler, see <a class="reference internal" href="mapper_config.html#simple-validators"><em>Simple Validators</em></a></li>
591
596
<li>Within the  <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_flush" title="sqlalchemy.orm.events.SessionEvents.before_flush"><tt class="xref py py-meth docutils literal"><span class="pre">SessionEvents.before_flush()</span></tt></a> event.</li>
592
597
</ul>
598
603
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
599
604
<li><strong>mapper</strong> &#8211; the <a class="reference internal" href="mapper_config.html#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> which is the target
600
605
of this event.</li>
601
 
<li><strong>connection</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> being used to
 
606
<li><strong>connection</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> being used to
602
607
emit UPDATE statements for this instance.  This
603
608
provides a handle into the current transaction on the
604
609
target database specific to this instance.</li>
634
639
a handle to the current <a class="reference internal" href="query.html#sqlalchemy.orm.query.Query" title="sqlalchemy.orm.query.Query"><tt class="xref py py-class docutils literal"><span class="pre">Query</span></tt></a> in progress as well
635
640
as additional state information.</li>
636
641
<li><strong>row</strong> &#8211; the result row being handled.  This may be
637
 
an actual <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.RowProxy" title="sqlalchemy.engine.base.RowProxy"><tt class="xref py py-class docutils literal"><span class="pre">RowProxy</span></tt></a> or may be a dictionary containing
 
642
an actual <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.RowProxy" title="sqlalchemy.engine.RowProxy"><tt class="xref py py-class docutils literal"><span class="pre">RowProxy</span></tt></a> or may be a dictionary containing
638
643
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects as keys.</li>
639
644
<li><strong>target</strong> &#8211; the mapped instance being populated.  If
640
645
the event is configured with <tt class="docutils literal"><span class="pre">raw=True</span></tt>, this will
673
678
<p class="first admonition-title">Warning</p>
674
679
<p>Mapper-level flush events are designed to operate <strong>on attributes
675
680
local to the immediate object being handled
676
 
and via SQL operations with the given</strong> <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> <strong>only.</strong>
677
 
Handlers here should <strong>not</strong> make alterations to the state of
678
 
the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> overall, and in general should not
 
681
and via SQL operations with the given</strong> <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a>
 
682
<strong>only.</strong> Handlers here should <strong>not</strong> make alterations to the
 
683
state of the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> overall, and in general should not
679
684
affect any <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> -mapped attributes, as
680
685
session cascade rules will not function properly, nor is it
681
686
always known if the related class has already been handled.
684
689
<li><a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.add" title="sqlalchemy.orm.session.Session.add"><tt class="xref py py-meth docutils literal"><span class="pre">Session.add()</span></tt></a></li>
685
690
<li><a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.delete" title="sqlalchemy.orm.session.Session.delete"><tt class="xref py py-meth docutils literal"><span class="pre">Session.delete()</span></tt></a></li>
686
691
<li>Mapped collection append, add, remove, delete, discard, etc.</li>
687
 
<li>Mapped relationship attribute set/del events, i.e. <tt class="docutils literal"><span class="pre">someobject.related</span> <span class="pre">=</span> <span class="pre">someotherobject</span></tt></li>
 
692
<li>Mapped relationship attribute set/del events,
 
693
i.e. <tt class="docutils literal"><span class="pre">someobject.related</span> <span class="pre">=</span> <span class="pre">someotherobject</span></tt></li>
688
694
</ul>
689
695
<p>Operations which manipulate the state of the object
690
696
relative to other objects are better handled:</p>
691
697
<ul class="last simple">
692
 
<li>In the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the mapped object itself, or another method
693
 
designed to establish some particular state.</li>
 
698
<li>In the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the mapped object itself,
 
699
or another method designed to establish some particular state.</li>
694
700
<li>In a <tt class="docutils literal"><span class="pre">&#64;validates</span></tt> handler, see <a class="reference internal" href="mapper_config.html#simple-validators"><em>Simple Validators</em></a></li>
695
701
<li>Within the  <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_flush" title="sqlalchemy.orm.events.SessionEvents.before_flush"><tt class="xref py py-meth docutils literal"><span class="pre">SessionEvents.before_flush()</span></tt></a> event.</li>
696
702
</ul>
702
708
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
703
709
<li><strong>mapper</strong> &#8211; the <a class="reference internal" href="mapper_config.html#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> which is the target
704
710
of this event.</li>
705
 
<li><strong>connection</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> being used to
 
711
<li><strong>connection</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> being used to
706
712
emit DELETE statements for this instance.  This
707
713
provides a handle into the current transaction on the
708
714
target database specific to this instance.</li>
741
747
<p class="first admonition-title">Warning</p>
742
748
<p>Mapper-level flush events are designed to operate <strong>on attributes
743
749
local to the immediate object being handled
744
 
and via SQL operations with the given</strong> <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> <strong>only.</strong>
745
 
Handlers here should <strong>not</strong> make alterations to the state of
746
 
the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> overall, and in general should not
747
 
affect any <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> -mapped attributes, as
748
 
session cascade rules will not function properly, nor is it
749
 
always known if the related class has already been handled.
750
 
Operations that <strong>are not supported in mapper events</strong> include:</p>
 
750
and via SQL operations with the given</strong>
 
751
<a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> <strong>only.</strong> Handlers here should <strong>not</strong> make
 
752
alterations to the state of the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> overall, and
 
753
in general should not affect any <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> -mapped
 
754
attributes, as session cascade rules will not function properly,
 
755
nor is it always known if the related class has already been
 
756
handled. Operations that <strong>are not supported in mapper
 
757
events</strong> include:</p>
751
758
<ul class="simple">
752
759
<li><a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.add" title="sqlalchemy.orm.session.Session.add"><tt class="xref py py-meth docutils literal"><span class="pre">Session.add()</span></tt></a></li>
753
760
<li><a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.delete" title="sqlalchemy.orm.session.Session.delete"><tt class="xref py py-meth docutils literal"><span class="pre">Session.delete()</span></tt></a></li>
754
761
<li>Mapped collection append, add, remove, delete, discard, etc.</li>
755
 
<li>Mapped relationship attribute set/del events, i.e. <tt class="docutils literal"><span class="pre">someobject.related</span> <span class="pre">=</span> <span class="pre">someotherobject</span></tt></li>
 
762
<li>Mapped relationship attribute set/del events,
 
763
i.e. <tt class="docutils literal"><span class="pre">someobject.related</span> <span class="pre">=</span> <span class="pre">someotherobject</span></tt></li>
756
764
</ul>
757
765
<p>Operations which manipulate the state of the object
758
766
relative to other objects are better handled:</p>
759
767
<ul class="last simple">
760
 
<li>In the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the mapped object itself, or another method
761
 
designed to establish some particular state.</li>
 
768
<li>In the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the mapped object itself, or
 
769
another method designed to establish some particular state.</li>
762
770
<li>In a <tt class="docutils literal"><span class="pre">&#64;validates</span></tt> handler, see <a class="reference internal" href="mapper_config.html#simple-validators"><em>Simple Validators</em></a></li>
763
771
<li>Within the  <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_flush" title="sqlalchemy.orm.events.SessionEvents.before_flush"><tt class="xref py py-meth docutils literal"><span class="pre">SessionEvents.before_flush()</span></tt></a> event.</li>
764
772
</ul>
770
778
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
771
779
<li><strong>mapper</strong> &#8211; the <a class="reference internal" href="mapper_config.html#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> which is the target
772
780
of this event.</li>
773
 
<li><strong>connection</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> being used to
 
781
<li><strong>connection</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> being used to
774
782
emit INSERT statements for this instance.  This
775
783
provides a handle into the current transaction on the
776
784
target database specific to this instance.</li>
826
834
<p class="first admonition-title">Warning</p>
827
835
<p>Mapper-level flush events are designed to operate <strong>on attributes
828
836
local to the immediate object being handled
829
 
and via SQL operations with the given</strong> <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> <strong>only.</strong>
830
 
Handlers here should <strong>not</strong> make alterations to the state of
831
 
the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> overall, and in general should not
 
837
and via SQL operations with the given</strong> <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a>
 
838
<strong>only.</strong> Handlers here should <strong>not</strong> make alterations to the
 
839
state of the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> overall, and in general should not
832
840
affect any <a class="reference internal" href="relationships.html#sqlalchemy.orm.relationship" title="sqlalchemy.orm.relationship"><tt class="xref py py-func docutils literal"><span class="pre">relationship()</span></tt></a> -mapped attributes, as
833
841
session cascade rules will not function properly, nor is it
834
842
always known if the related class has already been handled.
837
845
<li><a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.add" title="sqlalchemy.orm.session.Session.add"><tt class="xref py py-meth docutils literal"><span class="pre">Session.add()</span></tt></a></li>
838
846
<li><a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.delete" title="sqlalchemy.orm.session.Session.delete"><tt class="xref py py-meth docutils literal"><span class="pre">Session.delete()</span></tt></a></li>
839
847
<li>Mapped collection append, add, remove, delete, discard, etc.</li>
840
 
<li>Mapped relationship attribute set/del events, i.e. <tt class="docutils literal"><span class="pre">someobject.related</span> <span class="pre">=</span> <span class="pre">someotherobject</span></tt></li>
 
848
<li>Mapped relationship attribute set/del events,
 
849
i.e. <tt class="docutils literal"><span class="pre">someobject.related</span> <span class="pre">=</span> <span class="pre">someotherobject</span></tt></li>
841
850
</ul>
842
851
<p>Operations which manipulate the state of the object
843
852
relative to other objects are better handled:</p>
844
853
<ul class="last simple">
845
 
<li>In the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the mapped object itself, or another method
846
 
designed to establish some particular state.</li>
 
854
<li>In the <tt class="docutils literal"><span class="pre">__init__()</span></tt> method of the mapped object itself,
 
855
or another method designed to establish some particular state.</li>
847
856
<li>In a <tt class="docutils literal"><span class="pre">&#64;validates</span></tt> handler, see <a class="reference internal" href="mapper_config.html#simple-validators"><em>Simple Validators</em></a></li>
848
857
<li>Within the  <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_flush" title="sqlalchemy.orm.events.SessionEvents.before_flush"><tt class="xref py py-meth docutils literal"><span class="pre">SessionEvents.before_flush()</span></tt></a> event.</li>
849
858
</ul>
855
864
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
856
865
<li><strong>mapper</strong> &#8211; the <a class="reference internal" href="mapper_config.html#sqlalchemy.orm.mapper.Mapper" title="sqlalchemy.orm.mapper.Mapper"><tt class="xref py py-class docutils literal"><span class="pre">Mapper</span></tt></a> which is the target
857
866
of this event.</li>
858
 
<li><strong>connection</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> being used to
 
867
<li><strong>connection</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> being used to
859
868
emit UPDATE statements for this instance.  This
860
869
provides a handle into the current transaction on the
861
870
target database specific to this instance.</li>
892
901
a handle to the current <a class="reference internal" href="query.html#sqlalchemy.orm.query.Query" title="sqlalchemy.orm.query.Query"><tt class="xref py py-class docutils literal"><span class="pre">Query</span></tt></a> in progress as well
893
902
as additional state information.</li>
894
903
<li><strong>row</strong> &#8211; the result row being handled.  This may be
895
 
an actual <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.RowProxy" title="sqlalchemy.engine.base.RowProxy"><tt class="xref py py-class docutils literal"><span class="pre">RowProxy</span></tt></a> or may be a dictionary containing
 
904
an actual <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.RowProxy" title="sqlalchemy.engine.RowProxy"><tt class="xref py py-class docutils literal"><span class="pre">RowProxy</span></tt></a> or may be a dictionary containing
896
905
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects as keys.</li>
897
906
<li><strong>class_</strong> &#8211; the mapped class.</li>
898
907
</ul>
937
946
<tt class="descname">mapper_configured</tt><big>(</big><em>mapper</em>, <em>class_</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.events.MapperEvents.mapper_configured" title="Permalink to this definition">¶</a></dt>
938
947
<dd><p>Called when the mapper for the class is fully configured.</p>
939
948
<p>This event is the latest phase of mapper construction, and
940
 
is invoked when the mapped classes are first used, so that relationships
941
 
between mappers can be resolved.   When the event is called,
942
 
the mapper should be in its final state.</p>
 
949
is invoked when the mapped classes are first used, so that
 
950
relationships between mappers can be resolved.   When the event is
 
951
called, the mapper should be in its final state.</p>
943
952
<p>While the configuration event normally occurs automatically,
944
953
it can be forced to occur ahead of time, in the case where the event
945
954
is needed before any actual mapper usage,  by using the
983
992
a handle to the current <a class="reference internal" href="query.html#sqlalchemy.orm.query.Query" title="sqlalchemy.orm.query.Query"><tt class="xref py py-class docutils literal"><span class="pre">Query</span></tt></a> in progress as well
984
993
as additional state information.</li>
985
994
<li><strong>row</strong> &#8211; the result row being handled.  This may be
986
 
an actual <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.RowProxy" title="sqlalchemy.engine.base.RowProxy"><tt class="xref py py-class docutils literal"><span class="pre">RowProxy</span></tt></a> or may be a dictionary containing
 
995
an actual <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.RowProxy" title="sqlalchemy.engine.RowProxy"><tt class="xref py py-class docutils literal"><span class="pre">RowProxy</span></tt></a> or may be a dictionary containing
987
996
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects as keys.</li>
988
997
<li><strong>target</strong> &#8211; the mapped instance.  If
989
998
the event is configured with <tt class="docutils literal"><span class="pre">raw=True</span></tt>, this will
1011
1020
It is called when the mapper first receives a row, before
1012
1021
the object identity or the instance itself has been derived
1013
1022
from that row.   The given row may or may not be a
1014
 
<a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.RowProxy" title="sqlalchemy.engine.base.RowProxy"><tt class="xref py py-class docutils literal"><span class="pre">RowProxy</span></tt></a> object - it will always be a dictionary-like
 
1023
<a class="reference internal" href="../core/connections.html#sqlalchemy.engine.RowProxy" title="sqlalchemy.engine.RowProxy"><tt class="xref py py-class docutils literal"><span class="pre">RowProxy</span></tt></a> object - it will always be a dictionary-like
1015
1024
object which contains mapped columns as keys.  The
1016
1025
returned object should also be a dictionary-like object
1017
1026
which recognizes mapped columns as keys.</p>
1026
1035
a handle to the current <a class="reference internal" href="query.html#sqlalchemy.orm.query.Query" title="sqlalchemy.orm.query.Query"><tt class="xref py py-class docutils literal"><span class="pre">Query</span></tt></a> in progress as well
1027
1036
as additional state information.</li>
1028
1037
<li><strong>row</strong> &#8211; the result row being handled.  This may be
1029
 
an actual <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.RowProxy" title="sqlalchemy.engine.base.RowProxy"><tt class="xref py py-class docutils literal"><span class="pre">RowProxy</span></tt></a> or may be a dictionary containing
 
1038
an actual <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.RowProxy" title="sqlalchemy.engine.RowProxy"><tt class="xref py py-class docutils literal"><span class="pre">RowProxy</span></tt></a> or may be a dictionary containing
1030
1039
<a class="reference internal" href="../core/schema.html#sqlalchemy.schema.Column" title="sqlalchemy.schema.Column"><tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt></a> objects as keys.</li>
1031
1040
</ul>
1032
1041
</td>
1081
1090
<tbody valign="top">
1082
1091
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1083
1092
<li><strong>propagate=False</strong> &#8211; When True, the event listener should
1084
 
be applied to all inheriting mappers as well as the
1085
 
mapper which is the target of this listener.</li>
 
1093
be applied to all inheriting classes as well as the
 
1094
class which is the target of this listener.</li>
1086
1095
<li><strong>raw=False</strong> &#8211; When True, the &#8220;target&#8221; argument passed
1087
1096
to applicable event listener functions will be the
1088
1097
instance&#8217;s <a class="reference internal" href="internals.html#sqlalchemy.orm.state.InstanceState" title="sqlalchemy.orm.state.InstanceState"><tt class="xref py py-class docutils literal"><span class="pre">InstanceState</span></tt></a> management
1291
1300
</div>
1292
1301
<p>The <a class="reference internal" href="../core/event.html#sqlalchemy.event.listen" title="sqlalchemy.event.listen"><tt class="xref py py-func docutils literal"><span class="pre">listen()</span></tt></a> function will accept
1293
1302
<a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> objects as well as the return result
1294
 
of <a class="reference internal" href="session.html#sqlalchemy.orm.session.sessionmaker" title="sqlalchemy.orm.session.sessionmaker"><tt class="xref py py-func docutils literal"><span class="pre">sessionmaker()</span></tt></a> and <a class="reference internal" href="session.html#sqlalchemy.orm.scoped_session" title="sqlalchemy.orm.scoped_session"><tt class="xref py py-func docutils literal"><span class="pre">scoped_session()</span></tt></a>.</p>
 
1303
of <tt class="xref py py-func docutils literal"><span class="pre">sessionmaker()</span></tt> and <tt class="xref py py-func docutils literal"><span class="pre">scoped_session()</span></tt>.</p>
1295
1304
<p>Additionally, it accepts the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> class which
1296
1305
will apply listeners to all <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> instances
1297
1306
globally.</p>
1300
1309
<tt class="descname">after_attach</tt><big>(</big><em>session</em>, <em>instance</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.events.SessionEvents.after_attach" title="Permalink to this definition">¶</a></dt>
1301
1310
<dd><p>Execute after an instance is attached to a session.</p>
1302
1311
<p>This is called after an add, delete or merge.</p>
 
1312
<div class="admonition note">
 
1313
<p class="first admonition-title">Note</p>
 
1314
<p class="last">As of 0.8, this event fires off <em>after</em> the item
 
1315
has been fully associated with the session, which is
 
1316
different than previous releases.  For event
 
1317
handlers that require the object not yet
 
1318
be part of session state (such as handlers which
 
1319
may autoflush while the target object is not
 
1320
yet complete) consider the
 
1321
new <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_attach" title="sqlalchemy.orm.events.SessionEvents.before_attach"><tt class="xref py py-meth docutils literal"><span class="pre">before_attach()</span></tt></a> event.</p>
 
1322
</div>
 
1323
<div class="admonition-see-also admonition seealso">
 
1324
<p class="first admonition-title">See also</p>
 
1325
<p class="last"><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_attach" title="sqlalchemy.orm.events.SessionEvents.before_attach"><tt class="xref py py-meth docutils literal"><span class="pre">before_attach()</span></tt></a></p>
 
1326
</div>
1303
1327
</dd></dl>
1304
1328
 
1305
1329
<dl class="method">
1313
1337
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1314
1338
<li><strong>session</strong> &#8211; The target <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a>.</li>
1315
1339
<li><strong>transaction</strong> &#8211; The <a class="reference internal" href="session.html#sqlalchemy.orm.session.SessionTransaction" title="sqlalchemy.orm.session.SessionTransaction"><tt class="xref py py-class docutils literal"><span class="pre">SessionTransaction</span></tt></a>.</li>
1316
 
<li><strong>connection</strong> &#8211; The <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.Connection" title="sqlalchemy.engine.base.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> object
 
1340
<li><strong>connection</strong> &#8211; The <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.Connection" title="sqlalchemy.engine.Connection"><tt class="xref py py-class docutils literal"><span class="pre">Connection</span></tt></a> object
1317
1341
which will be used for SQL statements.</li>
1318
1342
</ul>
1319
1343
</td>
1320
1344
</tr>
1321
1345
</tbody>
1322
1346
</table>
 
1347
<div class="admonition-see-also admonition seealso">
 
1348
<p class="first admonition-title">See also</p>
 
1349
<p><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_commit" title="sqlalchemy.orm.events.SessionEvents.before_commit"><tt class="xref py py-meth docutils literal"><span class="pre">before_commit()</span></tt></a></p>
 
1350
<p><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_commit" title="sqlalchemy.orm.events.SessionEvents.after_commit"><tt class="xref py py-meth docutils literal"><span class="pre">after_commit()</span></tt></a></p>
 
1351
<p><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_transaction_create" title="sqlalchemy.orm.events.SessionEvents.after_transaction_create"><tt class="xref py py-meth docutils literal"><span class="pre">after_transaction_create()</span></tt></a></p>
 
1352
<p class="last"><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_transaction_end" title="sqlalchemy.orm.events.SessionEvents.after_transaction_end"><tt class="xref py py-meth docutils literal"><span class="pre">after_transaction_end()</span></tt></a></p>
 
1353
</div>
1323
1354
</dd></dl>
1324
1355
 
1325
1356
<dl class="method">
1336
1367
called upon.</li>
1337
1368
<li><strong>query_context</strong> &#8211; The <a class="reference internal" href="internals.html#sqlalchemy.orm.query.QueryContext" title="sqlalchemy.orm.query.QueryContext"><tt class="xref py py-class docutils literal"><span class="pre">QueryContext</span></tt></a> object, corresponding
1338
1369
to the invocation of an ORM query.</li>
1339
 
<li><strong>result</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.ResultProxy" title="sqlalchemy.engine.base.ResultProxy"><tt class="xref py py-class docutils literal"><span class="pre">ResultProxy</span></tt></a> returned as a result of the
 
1370
<li><strong>result</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.ResultProxy" title="sqlalchemy.engine.ResultProxy"><tt class="xref py py-class docutils literal"><span class="pre">ResultProxy</span></tt></a> returned as a result of the
1340
1371
bulk DELETE operation.</li>
1341
1372
</ul>
1342
1373
</td>
1359
1390
called upon.</li>
1360
1391
<li><strong>query_context</strong> &#8211; The <a class="reference internal" href="internals.html#sqlalchemy.orm.query.QueryContext" title="sqlalchemy.orm.query.QueryContext"><tt class="xref py py-class docutils literal"><span class="pre">QueryContext</span></tt></a> object, corresponding
1361
1392
to the invocation of an ORM query.</li>
1362
 
<li><strong>result</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.base.ResultProxy" title="sqlalchemy.engine.base.ResultProxy"><tt class="xref py py-class docutils literal"><span class="pre">ResultProxy</span></tt></a> returned as a result of the
 
1393
<li><strong>result</strong> &#8211; the <a class="reference internal" href="../core/connections.html#sqlalchemy.engine.ResultProxy" title="sqlalchemy.engine.ResultProxy"><tt class="xref py py-class docutils literal"><span class="pre">ResultProxy</span></tt></a> returned as a result of the
1363
1394
bulk UPDATE operation.</li>
1364
1395
</ul>
1365
1396
</td>
1372
1403
<dt id="sqlalchemy.orm.events.SessionEvents.after_commit">
1373
1404
<tt class="descname">after_commit</tt><big>(</big><em>session</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.events.SessionEvents.after_commit" title="Permalink to this definition">¶</a></dt>
1374
1405
<dd><p>Execute after a commit has occurred.</p>
1375
 
<p>Note that this may not be per-flush if a longer running
1376
 
transaction is ongoing.</p>
 
1406
<div class="admonition note">
 
1407
<p class="first admonition-title">Note</p>
 
1408
<p class="last">The <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_commit" title="sqlalchemy.orm.events.SessionEvents.after_commit"><tt class="xref py py-meth docutils literal"><span class="pre">after_commit()</span></tt></a> hook is <em>not</em> per-flush,
 
1409
that is, the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> can emit SQL to the database
 
1410
many times within the scope of a transaction.
 
1411
For interception of these events, use the <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_flush" title="sqlalchemy.orm.events.SessionEvents.before_flush"><tt class="xref py py-meth docutils literal"><span class="pre">before_flush()</span></tt></a>,
 
1412
<a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_flush" title="sqlalchemy.orm.events.SessionEvents.after_flush"><tt class="xref py py-meth docutils literal"><span class="pre">after_flush()</span></tt></a>, or <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_flush_postexec" title="sqlalchemy.orm.events.SessionEvents.after_flush_postexec"><tt class="xref py py-meth docutils literal"><span class="pre">after_flush_postexec()</span></tt></a>
 
1413
events.</p>
 
1414
</div>
 
1415
<div class="admonition note">
 
1416
<p class="first admonition-title">Note</p>
 
1417
<p class="last">The <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> is not in an active tranasction
 
1418
when the <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_commit" title="sqlalchemy.orm.events.SessionEvents.after_commit"><tt class="xref py py-meth docutils literal"><span class="pre">after_commit()</span></tt></a> event is invoked, and therefore
 
1419
can not emit SQL.  To emit SQL corresponding to every transaction,
 
1420
use the <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_commit" title="sqlalchemy.orm.events.SessionEvents.before_commit"><tt class="xref py py-meth docutils literal"><span class="pre">before_commit()</span></tt></a> event.</p>
 
1421
</div>
1377
1422
<table class="docutils field-list" frame="void" rules="none">
1378
1423
<col class="field-name" />
1379
1424
<col class="field-body" />
1382
1427
</tr>
1383
1428
</tbody>
1384
1429
</table>
 
1430
<div class="admonition-see-also admonition seealso">
 
1431
<p class="first admonition-title">See also</p>
 
1432
<p><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_commit" title="sqlalchemy.orm.events.SessionEvents.before_commit"><tt class="xref py py-meth docutils literal"><span class="pre">before_commit()</span></tt></a></p>
 
1433
<p><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_begin" title="sqlalchemy.orm.events.SessionEvents.after_begin"><tt class="xref py py-meth docutils literal"><span class="pre">after_begin()</span></tt></a></p>
 
1434
<p><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_transaction_create" title="sqlalchemy.orm.events.SessionEvents.after_transaction_create"><tt class="xref py py-meth docutils literal"><span class="pre">after_transaction_create()</span></tt></a></p>
 
1435
<p class="last"><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_transaction_end" title="sqlalchemy.orm.events.SessionEvents.after_transaction_end"><tt class="xref py py-meth docutils literal"><span class="pre">after_transaction_end()</span></tt></a></p>
 
1436
</div>
1385
1437
</dd></dl>
1386
1438
 
1387
1439
<dl class="method">
1405
1457
</tr>
1406
1458
</tbody>
1407
1459
</table>
 
1460
<div class="admonition-see-also admonition seealso">
 
1461
<p class="first admonition-title">See also</p>
 
1462
<p><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_flush" title="sqlalchemy.orm.events.SessionEvents.before_flush"><tt class="xref py py-meth docutils literal"><span class="pre">before_flush()</span></tt></a></p>
 
1463
<p class="last"><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_flush_postexec" title="sqlalchemy.orm.events.SessionEvents.after_flush_postexec"><tt class="xref py py-meth docutils literal"><span class="pre">after_flush_postexec()</span></tt></a></p>
 
1464
</div>
1408
1465
</dd></dl>
1409
1466
 
1410
1467
<dl class="method">
1429
1486
</tr>
1430
1487
</tbody>
1431
1488
</table>
 
1489
<div class="admonition-see-also admonition seealso">
 
1490
<p class="first admonition-title">See also</p>
 
1491
<p><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_flush" title="sqlalchemy.orm.events.SessionEvents.before_flush"><tt class="xref py py-meth docutils literal"><span class="pre">before_flush()</span></tt></a></p>
 
1492
<p class="last"><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_flush" title="sqlalchemy.orm.events.SessionEvents.after_flush"><tt class="xref py py-meth docutils literal"><span class="pre">after_flush()</span></tt></a></p>
 
1493
</div>
1432
1494
</dd></dl>
1433
1495
 
1434
1496
<dl class="method">
1478
1540
<tbody valign="top">
1479
1541
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
1480
1542
<li><strong>session</strong> &#8211; The target <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a>.</li>
1481
 
<li><strong>previous_transaction</strong> &#8211; The <a class="reference internal" href="session.html#sqlalchemy.orm.session.SessionTransaction" title="sqlalchemy.orm.session.SessionTransaction"><tt class="xref py py-class docutils literal"><span class="pre">SessionTransaction</span></tt></a> transactional
1482
 
marker object which was just closed.   The current <a class="reference internal" href="session.html#sqlalchemy.orm.session.SessionTransaction" title="sqlalchemy.orm.session.SessionTransaction"><tt class="xref py py-class docutils literal"><span class="pre">SessionTransaction</span></tt></a>
1483
 
for the given <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> is available via the
1484
 
<a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.transaction" title="sqlalchemy.orm.session.Session.transaction"><tt class="xref py py-attr docutils literal"><span class="pre">Session.transaction</span></tt></a> attribute.</li>
 
1543
<li><strong>previous_transaction</strong> &#8211; The <a class="reference internal" href="session.html#sqlalchemy.orm.session.SessionTransaction" title="sqlalchemy.orm.session.SessionTransaction"><tt class="xref py py-class docutils literal"><span class="pre">SessionTransaction</span></tt></a></li>
1485
1544
</ul>
1486
1545
</td>
1487
1546
</tr>
1488
1547
</tbody>
1489
1548
</table>
 
1549
<p>transactional marker object which was just closed.   The current
 
1550
<a class="reference internal" href="session.html#sqlalchemy.orm.session.SessionTransaction" title="sqlalchemy.orm.session.SessionTransaction"><tt class="xref py py-class docutils literal"><span class="pre">SessionTransaction</span></tt></a> for the given <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> is
 
1551
available via the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session.transaction" title="sqlalchemy.orm.session.Session.transaction"><tt class="xref py py-attr docutils literal"><span class="pre">Session.transaction</span></tt></a> attribute.</p>
1490
1552
<p class="versionadded">
1491
1553
<span class="versionmodified">New in version 0.7.3.</span></p>
1492
1554
</dd></dl>
1493
1555
 
1494
1556
<dl class="method">
 
1557
<dt id="sqlalchemy.orm.events.SessionEvents.after_transaction_create">
 
1558
<tt class="descname">after_transaction_create</tt><big>(</big><em>session</em>, <em>transaction</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.events.SessionEvents.after_transaction_create" title="Permalink to this definition">¶</a></dt>
 
1559
<dd><p>Execute when a new <a class="reference internal" href="session.html#sqlalchemy.orm.session.SessionTransaction" title="sqlalchemy.orm.session.SessionTransaction"><tt class="xref py py-class docutils literal"><span class="pre">SessionTransaction</span></tt></a> is created.</p>
 
1560
<p>This event differs from <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_begin" title="sqlalchemy.orm.events.SessionEvents.after_begin"><tt class="xref py py-meth docutils literal"><span class="pre">after_begin()</span></tt></a>
 
1561
in that it occurs for each <a class="reference internal" href="session.html#sqlalchemy.orm.session.SessionTransaction" title="sqlalchemy.orm.session.SessionTransaction"><tt class="xref py py-class docutils literal"><span class="pre">SessionTransaction</span></tt></a>
 
1562
overall, as opposed to when transactions are begun
 
1563
on individual database connections.  It is also invoked
 
1564
for nested transactions and subtransactions, and is always
 
1565
matched by a corresponding
 
1566
<a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_transaction_end" title="sqlalchemy.orm.events.SessionEvents.after_transaction_end"><tt class="xref py py-meth docutils literal"><span class="pre">after_transaction_end()</span></tt></a> event
 
1567
(assuming normal operation of the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a>).</p>
 
1568
<table class="docutils field-list" frame="void" rules="none">
 
1569
<col class="field-name" />
 
1570
<col class="field-body" />
 
1571
<tbody valign="top">
 
1572
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
1573
<li><strong>session</strong> &#8211; the target <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a>.</li>
 
1574
<li><strong>transaction</strong> &#8211; the target <a class="reference internal" href="session.html#sqlalchemy.orm.session.SessionTransaction" title="sqlalchemy.orm.session.SessionTransaction"><tt class="xref py py-class docutils literal"><span class="pre">SessionTransaction</span></tt></a>.</li>
 
1575
</ul>
 
1576
</td>
 
1577
</tr>
 
1578
</tbody>
 
1579
</table>
 
1580
<p class="versionadded">
 
1581
<span class="versionmodified">New in version 0.8.</span></p>
 
1582
<div class="admonition-see-also admonition seealso">
 
1583
<p class="first admonition-title">See also</p>
 
1584
<p class="last"><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_transaction_end" title="sqlalchemy.orm.events.SessionEvents.after_transaction_end"><tt class="xref py py-meth docutils literal"><span class="pre">after_transaction_end()</span></tt></a></p>
 
1585
</div>
 
1586
</dd></dl>
 
1587
 
 
1588
<dl class="method">
 
1589
<dt id="sqlalchemy.orm.events.SessionEvents.after_transaction_end">
 
1590
<tt class="descname">after_transaction_end</tt><big>(</big><em>session</em>, <em>transaction</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.events.SessionEvents.after_transaction_end" title="Permalink to this definition">¶</a></dt>
 
1591
<dd><p>Execute when the span of a <a class="reference internal" href="session.html#sqlalchemy.orm.session.SessionTransaction" title="sqlalchemy.orm.session.SessionTransaction"><tt class="xref py py-class docutils literal"><span class="pre">SessionTransaction</span></tt></a> ends.</p>
 
1592
<p>This event differs from <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_commit" title="sqlalchemy.orm.events.SessionEvents.after_commit"><tt class="xref py py-meth docutils literal"><span class="pre">after_commit()</span></tt></a>
 
1593
in that it corresponds to all <a class="reference internal" href="session.html#sqlalchemy.orm.session.SessionTransaction" title="sqlalchemy.orm.session.SessionTransaction"><tt class="xref py py-class docutils literal"><span class="pre">SessionTransaction</span></tt></a>
 
1594
objects in use, including those for nested transactions
 
1595
and subtransactions, and is always matched by a corresponding
 
1596
<a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_transaction_create" title="sqlalchemy.orm.events.SessionEvents.after_transaction_create"><tt class="xref py py-meth docutils literal"><span class="pre">after_transaction_create()</span></tt></a> event.</p>
 
1597
<table class="docutils field-list" frame="void" rules="none">
 
1598
<col class="field-name" />
 
1599
<col class="field-body" />
 
1600
<tbody valign="top">
 
1601
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
 
1602
<li><strong>session</strong> &#8211; the target <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a>.</li>
 
1603
<li><strong>transaction</strong> &#8211; the target <a class="reference internal" href="session.html#sqlalchemy.orm.session.SessionTransaction" title="sqlalchemy.orm.session.SessionTransaction"><tt class="xref py py-class docutils literal"><span class="pre">SessionTransaction</span></tt></a>.</li>
 
1604
</ul>
 
1605
</td>
 
1606
</tr>
 
1607
</tbody>
 
1608
</table>
 
1609
<p class="versionadded">
 
1610
<span class="versionmodified">New in version 0.8.</span></p>
 
1611
<div class="admonition-see-also admonition seealso">
 
1612
<p class="first admonition-title">See also</p>
 
1613
<p class="last"><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_transaction_create" title="sqlalchemy.orm.events.SessionEvents.after_transaction_create"><tt class="xref py py-meth docutils literal"><span class="pre">after_transaction_create()</span></tt></a></p>
 
1614
</div>
 
1615
</dd></dl>
 
1616
 
 
1617
<dl class="method">
 
1618
<dt id="sqlalchemy.orm.events.SessionEvents.before_attach">
 
1619
<tt class="descname">before_attach</tt><big>(</big><em>session</em>, <em>instance</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.events.SessionEvents.before_attach" title="Permalink to this definition">¶</a></dt>
 
1620
<dd><p>Execute before an instance is attached to a session.</p>
 
1621
<p>This is called before an add, delete or merge causes
 
1622
the object to be part of the session.</p>
 
1623
<p class="versionadded">
 
1624
<span class="versionmodified">New in version 0.8.: </span>Note that <a class="reference internal" href="deprecated.html#sqlalchemy.orm.interfaces.SessionExtension.after_attach" title="sqlalchemy.orm.interfaces.SessionExtension.after_attach"><tt class="xref py py-meth docutils literal"><span class="pre">after_attach()</span></tt></a> now
 
1625
fires off after the item is part of the session.
 
1626
<a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_attach" title="sqlalchemy.orm.events.SessionEvents.before_attach"><tt class="xref py py-meth docutils literal"><span class="pre">before_attach()</span></tt></a> is provided for those cases where
 
1627
the item should not yet be part of the session state.</p>
 
1628
<div class="admonition-see-also admonition seealso">
 
1629
<p class="first admonition-title">See also</p>
 
1630
<p class="last"><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_attach" title="sqlalchemy.orm.events.SessionEvents.after_attach"><tt class="xref py py-meth docutils literal"><span class="pre">after_attach()</span></tt></a></p>
 
1631
</div>
 
1632
</dd></dl>
 
1633
 
 
1634
<dl class="method">
1495
1635
<dt id="sqlalchemy.orm.events.SessionEvents.before_commit">
1496
1636
<tt class="descname">before_commit</tt><big>(</big><em>session</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.events.SessionEvents.before_commit" title="Permalink to this definition">¶</a></dt>
1497
1637
<dd><p>Execute before commit is called.</p>
1498
 
<p>Note that this may not be per-flush if a longer running
1499
 
transaction is ongoing.</p>
 
1638
<div class="admonition note">
 
1639
<p class="first admonition-title">Note</p>
 
1640
<p class="last">The <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_commit" title="sqlalchemy.orm.events.SessionEvents.before_commit"><tt class="xref py py-meth docutils literal"><span class="pre">before_commit()</span></tt></a> hook is <em>not</em> per-flush,
 
1641
that is, the <a class="reference internal" href="session.html#sqlalchemy.orm.session.Session" title="sqlalchemy.orm.session.Session"><tt class="xref py py-class docutils literal"><span class="pre">Session</span></tt></a> can emit SQL to the database
 
1642
many times within the scope of a transaction.
 
1643
For interception of these events, use the <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.before_flush" title="sqlalchemy.orm.events.SessionEvents.before_flush"><tt class="xref py py-meth docutils literal"><span class="pre">before_flush()</span></tt></a>,
 
1644
<a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_flush" title="sqlalchemy.orm.events.SessionEvents.after_flush"><tt class="xref py py-meth docutils literal"><span class="pre">after_flush()</span></tt></a>, or <a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_flush_postexec" title="sqlalchemy.orm.events.SessionEvents.after_flush_postexec"><tt class="xref py py-meth docutils literal"><span class="pre">after_flush_postexec()</span></tt></a>
 
1645
events.</p>
 
1646
</div>
1500
1647
<table class="docutils field-list" frame="void" rules="none">
1501
1648
<col class="field-name" />
1502
1649
<col class="field-body" />
1505
1652
</tr>
1506
1653
</tbody>
1507
1654
</table>
 
1655
<div class="admonition-see-also admonition seealso">
 
1656
<p class="first admonition-title">See also</p>
 
1657
<p><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_commit" title="sqlalchemy.orm.events.SessionEvents.after_commit"><tt class="xref py py-meth docutils literal"><span class="pre">after_commit()</span></tt></a></p>
 
1658
<p><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_begin" title="sqlalchemy.orm.events.SessionEvents.after_begin"><tt class="xref py py-meth docutils literal"><span class="pre">after_begin()</span></tt></a></p>
 
1659
<p><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_transaction_create" title="sqlalchemy.orm.events.SessionEvents.after_transaction_create"><tt class="xref py py-meth docutils literal"><span class="pre">after_transaction_create()</span></tt></a></p>
 
1660
<p class="last"><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_transaction_end" title="sqlalchemy.orm.events.SessionEvents.after_transaction_end"><tt class="xref py py-meth docutils literal"><span class="pre">after_transaction_end()</span></tt></a></p>
 
1661
</div>
1508
1662
</dd></dl>
1509
1663
 
1510
1664
<dl class="method">
1527
1681
</tr>
1528
1682
</tbody>
1529
1683
</table>
 
1684
<div class="admonition-see-also admonition seealso">
 
1685
<p class="first admonition-title">See also</p>
 
1686
<p><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_flush" title="sqlalchemy.orm.events.SessionEvents.after_flush"><tt class="xref py py-meth docutils literal"><span class="pre">after_flush()</span></tt></a></p>
 
1687
<p class="last"><a class="reference internal" href="#sqlalchemy.orm.events.SessionEvents.after_flush_postexec" title="sqlalchemy.orm.events.SessionEvents.after_flush_postexec"><tt class="xref py py-meth docutils literal"><span class="pre">after_flush_postexec()</span></tt></a></p>
 
1688
</div>
1530
1689
</dd></dl>
1531
1690
 
1532
1691
</dd></dl>
1541
1700
<p>The listeners here support being established against
1542
1701
any new style class, that is any object that is a subclass
1543
1702
of &#8216;type&#8217;.  Events will then be fired off for events
1544
 
against that class as well as all subclasses.
1545
 
&#8216;type&#8217; itself is also accepted as a target
1546
 
in which case the events fire for all classes.</p>
 
1703
against that class.  If the &#8220;propagate=True&#8221; flag is passed
 
1704
to event.listen(), the event will fire off for subclasses
 
1705
of that class as well.</p>
 
1706
<p>The Python <tt class="docutils literal"><span class="pre">type</span></tt> builtin is also accepted as a target,
 
1707
which when used has the effect of events being emitted
 
1708
for all classes.</p>
 
1709
<p>Note the &#8220;propagate&#8221; flag here is defaulted to <tt class="docutils literal"><span class="pre">True</span></tt>,
 
1710
unlike the other class level events where it defaults
 
1711
to <tt class="docutils literal"><span class="pre">False</span></tt>.  This means that new subclasses will also
 
1712
be the subject of these events, when a listener
 
1713
is established on a superclass.</p>
 
1714
<p class="versionchanged">
 
1715
<span class="versionmodified">Changed in version 0.8: </span>- events here will emit based
 
1716
on comparing the incoming class to the type of class
 
1717
passed to <a class="reference internal" href="../core/event.html#sqlalchemy.event.listen" title="sqlalchemy.event.listen"><tt class="xref py py-func docutils literal"><span class="pre">event.listen()</span></tt></a>.  Previously, the
 
1718
event would fire for any class unconditionally regardless
 
1719
of what class was sent for listening, despite
 
1720
documentation which stated the contrary.</p>
1547
1721
<dl class="method">
1548
1722
<dt id="sqlalchemy.orm.events.InstrumentationEvents.attribute_instrument">
1549
1723
<tt class="descname">attribute_instrument</tt><big>(</big><em>cls</em>, <em>key</em>, <em>inst</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.events.InstrumentationEvents.attribute_instrument" title="Permalink to this definition">¶</a></dt>
1555
1729
<tt class="descname">class_instrument</tt><big>(</big><em>cls</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.events.InstrumentationEvents.class_instrument" title="Permalink to this definition">¶</a></dt>
1556
1730
<dd><p>Called after the given class is instrumented.</p>
1557
1731
<p>To get at the <a class="reference internal" href="internals.html#sqlalchemy.orm.instrumentation.ClassManager" title="sqlalchemy.orm.instrumentation.ClassManager"><tt class="xref py py-class docutils literal"><span class="pre">ClassManager</span></tt></a>, use
1558
 
<a class="reference internal" href="session.html#sqlalchemy.orm.attributes.manager_of_class" title="sqlalchemy.orm.attributes.manager_of_class"><tt class="xref py py-func docutils literal"><span class="pre">manager_of_class()</span></tt></a>.</p>
 
1732
<tt class="xref py py-func docutils literal"><span class="pre">manager_of_class()</span></tt>.</p>
1559
1733
</dd></dl>
1560
1734
 
1561
1735
<dl class="method">
1563
1737
<tt class="descname">class_uninstrument</tt><big>(</big><em>cls</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.events.InstrumentationEvents.class_uninstrument" title="Permalink to this definition">¶</a></dt>
1564
1738
<dd><p>Called before the given class is uninstrumented.</p>
1565
1739
<p>To get at the <a class="reference internal" href="internals.html#sqlalchemy.orm.instrumentation.ClassManager" title="sqlalchemy.orm.instrumentation.ClassManager"><tt class="xref py py-class docutils literal"><span class="pre">ClassManager</span></tt></a>, use
1566
 
<a class="reference internal" href="session.html#sqlalchemy.orm.attributes.manager_of_class" title="sqlalchemy.orm.attributes.manager_of_class"><tt class="xref py py-func docutils literal"><span class="pre">manager_of_class()</span></tt></a>.</p>
1567
 
</dd></dl>
1568
 
 
1569
 
</dd></dl>
1570
 
 
1571
 
</div>
1572
 
<div class="section" id="alternate-class-instrumentation">
1573
 
<h2>Alternate Class Instrumentation<a class="headerlink" href="#alternate-class-instrumentation" title="Permalink to this headline">¶</a></h2>
1574
 
<dl class="class">
1575
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager">
1576
 
<em class="property">class </em><tt class="descclassname">sqlalchemy.orm.interfaces.</tt><tt class="descname">InstrumentationManager</tt><big>(</big><em>class_</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager" title="Permalink to this definition">¶</a></dt>
1577
 
<dd><p>User-defined class instrumentation extension.</p>
1578
 
<p><a class="reference internal" href="#sqlalchemy.orm.interfaces.InstrumentationManager" title="sqlalchemy.orm.interfaces.InstrumentationManager"><tt class="xref py py-class docutils literal"><span class="pre">InstrumentationManager</span></tt></a> can be subclassed in order
1579
 
to change
1580
 
how class instrumentation proceeds. This class exists for
1581
 
the purposes of integration with other object management
1582
 
frameworks which would like to entirely modify the
1583
 
instrumentation methodology of the ORM, and is not intended
1584
 
for regular usage.  For interception of class instrumentation
1585
 
events, see <a class="reference internal" href="#sqlalchemy.orm.events.InstrumentationEvents" title="sqlalchemy.orm.events.InstrumentationEvents"><tt class="xref py py-class docutils literal"><span class="pre">InstrumentationEvents</span></tt></a>.</p>
1586
 
<p>For an example of <a class="reference internal" href="#sqlalchemy.orm.interfaces.InstrumentationManager" title="sqlalchemy.orm.interfaces.InstrumentationManager"><tt class="xref py py-class docutils literal"><span class="pre">InstrumentationManager</span></tt></a>, see the
1587
 
example <a class="reference internal" href="examples.html#examples-instrumentation"><em>Attribute Instrumentation</em></a>.</p>
1588
 
<p>The API for this class should be considered as semi-stable,
1589
 
and may change slightly with new releases.</p>
1590
 
<dl class="method">
1591
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.dict_getter">
1592
 
<tt class="descname">dict_getter</tt><big>(</big><em>class_</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.dict_getter" title="Permalink to this definition">¶</a></dt>
1593
 
<dd></dd></dl>
1594
 
 
1595
 
<dl class="method">
1596
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.dispose">
1597
 
<tt class="descname">dispose</tt><big>(</big><em>class_</em>, <em>manager</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.dispose" title="Permalink to this definition">¶</a></dt>
1598
 
<dd></dd></dl>
1599
 
 
1600
 
<dl class="method">
1601
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.get_instance_dict">
1602
 
<tt class="descname">get_instance_dict</tt><big>(</big><em>class_</em>, <em>instance</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.get_instance_dict" title="Permalink to this definition">¶</a></dt>
1603
 
<dd></dd></dl>
1604
 
 
1605
 
<dl class="method">
1606
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.initialize_instance_dict">
1607
 
<tt class="descname">initialize_instance_dict</tt><big>(</big><em>class_</em>, <em>instance</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.initialize_instance_dict" title="Permalink to this definition">¶</a></dt>
1608
 
<dd></dd></dl>
1609
 
 
1610
 
<dl class="method">
1611
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.install_descriptor">
1612
 
<tt class="descname">install_descriptor</tt><big>(</big><em>class_</em>, <em>key</em>, <em>inst</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.install_descriptor" title="Permalink to this definition">¶</a></dt>
1613
 
<dd></dd></dl>
1614
 
 
1615
 
<dl class="method">
1616
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.install_member">
1617
 
<tt class="descname">install_member</tt><big>(</big><em>class_</em>, <em>key</em>, <em>implementation</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.install_member" title="Permalink to this definition">¶</a></dt>
1618
 
<dd></dd></dl>
1619
 
 
1620
 
<dl class="method">
1621
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.install_state">
1622
 
<tt class="descname">install_state</tt><big>(</big><em>class_</em>, <em>instance</em>, <em>state</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.install_state" title="Permalink to this definition">¶</a></dt>
1623
 
<dd></dd></dl>
1624
 
 
1625
 
<dl class="method">
1626
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.instrument_attribute">
1627
 
<tt class="descname">instrument_attribute</tt><big>(</big><em>class_</em>, <em>key</em>, <em>inst</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.instrument_attribute" title="Permalink to this definition">¶</a></dt>
1628
 
<dd></dd></dl>
1629
 
 
1630
 
<dl class="method">
1631
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.instrument_collection_class">
1632
 
<tt class="descname">instrument_collection_class</tt><big>(</big><em>class_</em>, <em>key</em>, <em>collection_class</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.instrument_collection_class" title="Permalink to this definition">¶</a></dt>
1633
 
<dd></dd></dl>
1634
 
 
1635
 
<dl class="method">
1636
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.manage">
1637
 
<tt class="descname">manage</tt><big>(</big><em>class_</em>, <em>manager</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.manage" title="Permalink to this definition">¶</a></dt>
1638
 
<dd></dd></dl>
1639
 
 
1640
 
<dl class="method">
1641
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.manager_getter">
1642
 
<tt class="descname">manager_getter</tt><big>(</big><em>class_</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.manager_getter" title="Permalink to this definition">¶</a></dt>
1643
 
<dd></dd></dl>
1644
 
 
1645
 
<dl class="method">
1646
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.post_configure_attribute">
1647
 
<tt class="descname">post_configure_attribute</tt><big>(</big><em>class_</em>, <em>key</em>, <em>inst</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.post_configure_attribute" title="Permalink to this definition">¶</a></dt>
1648
 
<dd></dd></dl>
1649
 
 
1650
 
<dl class="method">
1651
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.remove_state">
1652
 
<tt class="descname">remove_state</tt><big>(</big><em>class_</em>, <em>instance</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.remove_state" title="Permalink to this definition">¶</a></dt>
1653
 
<dd></dd></dl>
1654
 
 
1655
 
<dl class="method">
1656
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.state_getter">
1657
 
<tt class="descname">state_getter</tt><big>(</big><em>class_</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.state_getter" title="Permalink to this definition">¶</a></dt>
1658
 
<dd></dd></dl>
1659
 
 
1660
 
<dl class="method">
1661
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.uninstall_descriptor">
1662
 
<tt class="descname">uninstall_descriptor</tt><big>(</big><em>class_</em>, <em>key</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.uninstall_descriptor" title="Permalink to this definition">¶</a></dt>
1663
 
<dd></dd></dl>
1664
 
 
1665
 
<dl class="method">
1666
 
<dt id="sqlalchemy.orm.interfaces.InstrumentationManager.uninstall_member">
1667
 
<tt class="descname">uninstall_member</tt><big>(</big><em>class_</em>, <em>key</em><big>)</big><a class="headerlink" href="#sqlalchemy.orm.interfaces.InstrumentationManager.uninstall_member" title="Permalink to this definition">¶</a></dt>
1668
 
<dd></dd></dl>
 
1740
<tt class="xref py py-func docutils literal"><span class="pre">manager_of_class()</span></tt>.</p>
 
1741
</dd></dl>
1669
1742
 
1670
1743
</dd></dl>
1671
1744
 
1683
1756
        <a href="extensions/index.html" title="next chapter">ORM Extensions</a>
1684
1757
 
1685
1758
    <div id="docs-copyright">
1686
 
        &copy; <a href="../copyright.html">Copyright</a> 2007-2012, the SQLAlchemy authors and contributors.
 
1759
        &copy; <a href="../copyright.html">Copyright</a> 2007-2013, the SQLAlchemy authors and contributors.
1687
1760
        Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
1688
1761
    </div>
1689
1762
</div>