<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">I found difference in client|server cursors behaviour:[<a href="%5BBR">BR</a>]<br>
client - side cursor fills cursor.description after execute(), and server-side cursor leave description 'None' after execute() until call of fetch...().[<a href="%5BBR">BR</a>]<br>
I found it both on windows and linux, with postgres 8.1.2 and psycopg 2-2.0.51 (last stable version).[<a href="%5BBR">BR</a>]<br>
SA looks in cursor description <strong>before</strong> calling fetch - see base.py line 562.</p>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/431/test_pg.py">test_pg.py</a></p>
<p dir="auto"><strong>Migrated issue, originally created by Markus Meskanen (<a href="https://github.com/Mahi">@Mahi</a>)</strong></p>
<p dir="auto">Django has a <code class="notranslate">get_or_create()</code> method for times when you don't know if data for an entity already exists. There are multiple implementations available for SQLAlchemy at <a href="http://stackoverflow.com/questions/2546207/does-sqlalchemy-have-an-equivalent-of-djangos-get-or-create/" rel="nofollow">http://stackoverflow.com/questions/2546207/does-sqlalchemy-have-an-equivalent-of-djangos-get-or-create/</a>, but I thought it would be nice to have a native support for such widely used feature.</p>
<p dir="auto">I'm not sure of the ideal implementation, but one that pleases my eye is to add a keyword arugment for <code class="notranslate">one()</code> etc:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="session.query(Player).filter_by(id=my_player_id).one(create=True)"><pre class="notranslate"><code class="notranslate">session.query(Player).filter_by(id=my_player_id).one(create=True)
</code></pre></div>
<p dir="auto">Or simply add a new method:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="session.query(Player).filter_by(id=my_player_id).get_or_create()"><pre class="notranslate"><code class="notranslate">session.query(Player).filter_by(id=my_player_id).get_or_create()
</code></pre></div>