Immediate vs load-on-first-access availability
<p>The <a href="http://docs.sqlalchemy.org/en/rel_1_0/orm/tutorial.html#adding-and-updating-objects" rel="nofollow">docs say</a> (at the end of the linked section):</p>

<blockquote>
  <p>After the Session inserts new rows in the database, all newly generated identifiers and database-generated defaults become available on the instance, either immediately or via load-on-first-access.</p>
</blockquote>

<p>What's the difference between <code>immediately</code> and <code>load-on-first-access</code>? Doesn't SQLAlchemy know the new identifiers and defaults after it completed the <code>INSERT</code> operation, and so don't they become available even without reloading?</p>

<p><strong>immediately:</strong> SQLAlchemy gets a primary key from the database for each session object inserted and assigns it to the session object. The session object needs the primary key immediately since, prior to the transaction snapshot being committed, the object enters the persistent state and is added to the Identity Map collection which keys it on its primary key. <a href="http://pyvideo.org/pycon-us-2013/the-sqlalchemy-session-in-depth-0.html" rel="nofollow">[The SQLAlchemy Session - In Depth]</a></p>

<p><strong>load-on-first-access:</strong> database-generated defaults associated with an object may never be used in its session. So to conserve resources these are <a href="http://martinfowler.com/eaaCatalog/lazyLoad.html" rel="nofollow">lazy loaded</a> as needed.</p>

python sqlalchemy