Message from discussion
SQLite rollback() fails
Received: by 10.224.70.131 with SMTP id d3mr3183206qaj.0.1349269210149;
Wed, 03 Oct 2012 06:00:10 -0700 (PDT)
X-BeenThere: sqlalchemy@googlegroups.com
Received: by 10.229.135.3 with SMTP id l3ls1923809qct.6.gmail; Wed, 03 Oct
2012 06:00:06 -0700 (PDT)
Received: by 10.224.31.20 with SMTP id w20mr3178286qac.2.1349269206247;
Wed, 03 Oct 2012 06:00:06 -0700 (PDT)
Received: by 10.224.28.72 with SMTP id l8msqac;
Wed, 3 Oct 2012 02:21:20 -0700 (PDT)
Received: by 10.224.189.75 with SMTP id dd11mr2845897qab.6.1349256079893;
Wed, 03 Oct 2012 02:21:19 -0700 (PDT)
Received: by 10.224.189.75 with SMTP id dd11mr2845896qab.6.1349256079873;
Wed, 03 Oct 2012 02:21:19 -0700 (PDT)
Return-Path: <Gabor.Gom...@morganstanley.com>
Received: from pimtaint03.ms.com (pimtaint03.ms.com. [199.89.103.73])
by gmr-mx.google.com with ESMTPS id a27si742426qck.3.2012.10.03.02.21.19
(version=TLSv1/SSLv3 cipher=OTHER);
Wed, 03 Oct 2012 02:21:19 -0700 (PDT)
Received-SPF: pass (google.com: domain of Gabor.Gom...@morganstanley.com designates 199.89.103.73 as permitted sender) client-ip=199.89.103.73;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of Gabor.Gom...@morganstanley.com designates 199.89.103.73 as permitted sender) smtp.mail=Gabor.Gom...@morganstanley.com; dkim=pass (test mode) header...@morganstanley.com
Received: from pimtaint03.ms.com (localhost.ms.com [127.0.0.1])
by pimtaint03.ms.com (output Postfix) with ESMTP id 895AA2B344AF
for <sqlalchemy@googlegroups.com>; Wed, 3 Oct 2012 05:21:19 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=morganstanley.com;
s=p20120616; t=1349256079; x=1350465679;
bh=2fkd9TIYtTpjVY66N2ifgptIkg8U/K/ahhcAqZ6xJd8=;
h=Content-Transfer-Encoding:From:To:Subject:Date:Message-ID:
Content-Type:MIME-Version;
b=Mh3ajGHIiRNEq8uzcNMVl3NdDjHeczC5rNOoSmTXwmJlmhLYJZNveVKZ8N7XZ2elP
+gPwcmVF3CCOca7ZfmMLH6MYRrFV7EALisN/4FYbN03gKHxpLx/OGgVcY1MuMQowxo
TrvHyTQ5D2ohKTfFyU1CKgeYQjhbM06o4/hWG6iw=
Received: from ny00yyas01.ms.com (ny00yyas01.ms.com [10.185.97.156])
by pimtaint03.ms.com (internal Postfix) with ESMTP id 870FE2B3448B
for <sqlalchemy@googlegroups.com>; Wed, 3 Oct 2012 05:21:19 -0400 (EDT)
Received: from ny00yyas01.ms.com (localhost [127.0.0.1])
by ny00yyas01.ms.com (msa-out Postfix) with ESMTP id 7823997C0B5
for <sqlalchemy@googlegroups.com>; Wed, 3 Oct 2012 05:21:19 -0400 (EDT)
Received: from NPWEXGOB02.msad.ms.com (np212c1n1 [10.184.90.163])
by ny00yyas01.ms.com (mta-in Postfix) with ESMTP id 7572558C001
for <sqlalchemy@googlegroups.com>; Wed, 3 Oct 2012 05:21:19 -0400 (EDT)
Received: from OYWEX0203N4.msad.ms.com (10.208.118.84) by NPWEXGOB02.msad.ms.com (10.184.90.163) with Microsoft SMTP Server (TLS) id 8.3.245.1; Wed, 3 Oct 2012 05:21:19 -0400
Received: from OYWEX0202N3.msad.ms.com ([169.254.2.158]) by OYWEX0203N4.msad.ms.com ([169.254.4.117]) with mapi id 14.02.0298.004; Wed, 3 Oct 2012 10:21:17 +0100
Content-Transfer-Encoding: 7bit
From: "Gombas, Gabor" <Gabor.Gom...@morganstanley.com>
To: <sqlalchemy@googlegroups.com>
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4913
Subject: SQLite rollback() fails
Thread-Topic: SQLite rollback() fails
thread-index: Ac2hSFKRWVA+gxwVTi2MQdBFDVD0SA==
Date: Wed, 3 Oct 2012 09:21:16 +0000
Message-ID: <F685237642C8674A99FCFE0F4A4A217B07D5E...@OYWEX0202N3.msad.ms.com>
Accept-Language: en-GB, en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-mspolicyagent: version=1.0
x-originating-ip: [10.173.249.123]
Content-Type: multipart/alternative;
boundary="_000_F685237642C8674A99FCFE0F4A4A217B07D5E201OYWEX0202N3msad_"
MIME-Version: 1.0
X-EXCLAIMER-MD-CONFIG: be3bdf5c-71de-49fb-a1b7-ad6a6a1df5e2
--_000_F685237642C8674A99FCFE0F4A4A217B07D5E201OYWEX0202N3msad_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hi,
I've run into a rather interesting issue, where calling =
session.rollback() dies. The error I get with SQLA 0.7 is:
<class 'sqlalchemy.exc.InvalidRequestError'>: Can't attach instance <Foo =
at 0x2acf68808710>; another instance with key (<class 'module.Foo'>, =
(342,)) is already present in this session.
Traceback:
sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:672:rollback
sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:386:rollback
=
sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:417:_rollback_impl
=
sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:274:_restore_snapshot
=
sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:1620:_update_impl
sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:1648:_attach
0.8 gives a slightly different message, but I think it is essentially =
the same:
<type 'exceptions.AssertionError'>: A conflicting state is already =
present in the identity map for key (<class 'module.Foo'>, (342,))
Traceback:
sqlalchemy-default/lib/sqlalchemy/orm/session.py:637:rollback
sqlalchemy-default/lib/sqlalchemy/orm/session.py:346:rollback
=
sqlalchemy-default/lib/sqlalchemy/orm/session.py:377:_rollback_impl
=
sqlalchemy-default/lib/sqlalchemy/orm/session.py:233:_restore_snapshot
=
sqlalchemy-default/lib/sqlalchemy/orm/session.py:1578:_update_impl
sqlalchemy-default/lib/sqlalchemy/orm/identity.py:115:add
What I see when turning on query logging:
- The Foo object with primary key 342 is loaded (using a =
non-primary mapper, if that makes any difference), and then deleted. The =
session is flushed.
- A new object is created (this time using the primary mapper), =
and during INSERT, SQLite assigns the same primary key to it as the =
previously deleted object had (I can see that from subsequent SELECT =
statements referencing the new object; it would be nice if SQLA logged =
the primary key after an INSERT at debug level)
- An application error (unrelated to SQLAlchemy) occurs, which =
causes rollback() to be called
I have a reliable reproducer, but it is the unit test of a large =
application, so there are lots of possibly unrelated things going on. =
I've spent two days coming up with a standalone reproducer, but I've =
failed, that's why I'm sending this mail instead of opening a ticket.
Any ideas?
Gabor
-------------------------------------------------------------------------=
-
NOTICE: Morgan Stanley is not acting as a municipal advisor and the =
opinions or views contained herein are not intended to be, and do not =
constitute, advice within the meaning of Section 975 of the Dodd-Frank =
Wall Street Reform and Consumer Protection Act. If you have received =
this communication in error, please destroy all electronic and paper =
copies and notify the sender immediately. Mistransmission is not =
intended to waive confidentiality or privilege. Morgan Stanley reserves =
the right, to the extent permitted under applicable law, to monitor =
electronic communications. This message is subject to terms available at =
the following link: http://www.morganstanley.com/disclaimers. If you =
cannot access these links, please notify us by reply message and we will =
send the contents to you. By messaging with Morgan Stanley you consent =
to the foregoing.
--_000_F685237642C8674A99FCFE0F4A4A217B07D5E201OYWEX0202N3msad_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<HTML xmlns=3D"http://www.w3.org/TR/REC-html40" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word"><head><META =
content=3D"text/html; charset=3Dus-ascii" http-equiv=3D"Content-Type">
<meta content=3D"text/html; charset=3Dus-ascii" =
http-equiv=3D"Content-Type">
<meta content=3D"Microsoft Word 12 (filtered medium)" =
name=3D"Generator">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:657422578;
mso-list-type:hybrid;
mso-list-template-ids:1894553054 -163395350 67698691 67698693 67698689 =
67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
{mso-level-start-at:0;
mso-level-number-format:bullet;
mso-level-text:-;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-font-family:Calibri;
mso-bidi-font-family:"Times New Roman";}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head><BODY>
<DIV><SPAN STYLE=3D"FONT-SIZE: 7.5pt; COLOR: gray; mso-bidi-font-family: =
Arial"><FONT COLOR=3D"gray" FACE=3D"Arial" SIZE=3D"1"><SPAN =
STYLE=3D"FONT-SIZE: 14pt; FONT-FAMILY: 'Arial','sans-serif'"><FONT =
SIZE=3D"2"><FONT COLOR=3D"#000000" FACE=3D"Times New Roman" =
SIZE=3D"3"><FONT FACE=3D"Arial" SIZE=3D"1"><FONT SIZE=3D"2">
<div class=3D"WordSection1">
<p class=3D"MsoNormal">Hi,<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">I’ve run into a rather interesting issue, =
where calling session.rollback() dies. The error I get with SQLA 0.7 =
is:<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"><class =
'sqlalchemy.exc.InvalidRequestError'>: Can't attach instance <Foo =
at 0x2acf68808710>; another instance with key (<class =
'module.Foo'>, (342,)) is already present in this =
session.<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Traceback:<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> =
sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:672:rollback<o:p></o:p><=
/p>
<p class=3D"MsoNormal"> =
sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:386:rollback<o:p></o:p><=
/p>
<p class=3D"MsoNormal"> =
sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:417:_rollback_impl<o:p><=
/o:p></p>
<p class=3D"MsoNormal"> =
sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:274:_restore_snapshot<o:=
p></o:p></p>
<p class=3D"MsoNormal"> =
sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:1620:_update_impl<o:p></=
o:p></p>
<p class=3D"MsoNormal"> =
sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:1648:_attach<o:p></o:p><=
/p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">0.8 gives a slightly different message, but I =
think it is essentially the same:<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"><type 'exceptions.AssertionError'>: A =
conflicting state is already present in the identity map for key =
(<class 'module.Foo'>, (342,))<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Traceback:<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal"> =
sqlalchemy-default/lib/sqlalchemy/orm/session.py:637:rollback<o:p></o:p><=
/p>
<p class=3D"MsoNormal"> =
sqlalchemy-default/lib/sqlalchemy/orm/session.py:346:rollback<o:p></o:p><=
/p>
<p class=3D"MsoNormal"> =
sqlalchemy-default/lib/sqlalchemy/orm/session.py:377:_rollback_impl<o:p><=
/o:p></p>
<p class=3D"MsoNormal"> =
sqlalchemy-default/lib/sqlalchemy/orm/session.py:233:_restore_snapshot<o:=
p></o:p></p>
<p class=3D"MsoNormal"> =
sqlalchemy-default/lib/sqlalchemy/orm/session.py:1578:_update_impl<o:p></=
o:p></p>
<p class=3D"MsoNormal"> =
sqlalchemy-default/lib/sqlalchemy/orm/identity.py:115:add<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">What I see when turning on query =
logging:<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoListParagraph" style=3D"text-indent:-18.0pt;mso-list:l0 =
level1 lfo1"><![if !supportLists]><span style=3D"mso-list:Ignore">-<span =
style=3D"font:7.0pt "Times New =
Roman"">
</span></span><![endif]>The Foo object with primary key 342 is loaded =
(using a non-primary mapper, if that makes any difference), and then =
deleted. The session is flushed.<o:p></o:p></p>
<p class=3D"MsoListParagraph" style=3D"text-indent:-18.0pt;mso-list:l0 =
level1 lfo1"><![if !supportLists]><span style=3D"mso-list:Ignore">-<span =
style=3D"font:7.0pt "Times New =
Roman"">
</span></span><![endif]>A new object is created (this time using the =
primary mapper), and during INSERT, SQLite assigns the same primary key =
to it as the previously deleted object had (I can see that from =
subsequent SELECT statements referencing the new object;
it would be nice if SQLA logged the primary key after an INSERT at =
debug level)<o:p></o:p></p>
<p class=3D"MsoListParagraph" style=3D"text-indent:-18.0pt;mso-list:l0 =
level1 lfo1"><![if !supportLists]><span style=3D"mso-list:Ignore">-<span =
style=3D"font:7.0pt "Times New =
Roman"">
</span></span><![endif]>An application error (unrelated to SQLAlchemy) =
occurs, which causes rollback() to be called<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">I have a reliable reproducer, but it is the unit =
test of a large application, so there are lots of possibly unrelated =
things going on. I’ve spent two days coming up with a standalone =
reproducer, but I’ve failed, that’s why I’m sending =
this
mail instead of opening a ticket.<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Any ideas?<o:p></o:p></p>
<p class=3D"MsoNormal"><o:p> </o:p></p>
<p class=3D"MsoNormal">Gabor<o:p></o:p></p>
</div>
</FONT></FONT></FONT></FONT></SPAN></FONT></SPAN></DIV>
<DIV><SPAN STYLE=3D"FONT-SIZE: 7.5pt; COLOR: gray; mso-bidi-font-family: =
Arial"><FONT COLOR=3D"gray" FACE=3D"Arial" SIZE=3D"1"><SPAN =
STYLE=3D"FONT-SIZE: 14pt; FONT-FAMILY: 'Arial','sans-serif'"><FONT =
SIZE=3D"2"><FONT COLOR=3D"#000000" FACE=3D"Times New Roman" =
SIZE=3D"3"><FONT FACE=3D"Arial" SIZE=3D"1">
<HR>
</FONT></FONT></FONT></SPAN></FONT></SPAN></DIV>
<DIV><SPAN STYLE=3D"FONT-SIZE: 7.5pt; COLOR: gray; mso-bidi-font-family: =
Arial"><FONT FACE=3D"Arial"><SPAN STYLE=3D"FONT-SIZE: 14pt; FONT-FAMILY: =
'Arial','sans-serif'"><FONT FACE=3D"Times New Roman"><FONT =
FACE=3D"Arial"><FONT COLOR=3D"#808080" SIZE=3D"1">NOTICE: <SPAN =
STYLE=3D"FONT-SIZE: 7.5pt; COLOR: gray; mso-bidi-font-family: =
Arial"><FONT FACE=3D"Arial"><SPAN STYLE=3D"FONT-SIZE: 14pt; FONT-FAMILY: =
'Arial','sans-serif'"><FONT FACE=3D"Times New Roman"><FONT =
FACE=3D"Arial"><FONT SIZE=3D"1"><FONT COLOR=3D"#808080"><SPAN =
LANG=3D"EN-GB" STYLE=3D"FONT-SIZE: 9pt; FONT-FAMILY: =
'Arial','sans-serif'; mso-fareast-font-family: SimSun; =
mso-fareast-theme-font: minor-fareast; mso-ansi-language: EN-GB; =
mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><FONT =
SIZE=3D"1">Morgan Stanley is not acting as a municipal advisor and the =
opinions or views contained herein are not intended to be, and do not =
constitute, advice within the meaning of Section 975 of the Dodd-Frank =
Wall Street Reform and Consumer Protection Act. =
</FONT></SPAN></FONT></FONT></FONT></FONT></SPAN></FONT></SPAN>If you =
have received this communication in error, please destroy all electronic =
and paper copies and notify the sender immediately. Mistransmission is =
not intended to waive confidentiality or privilege. Morgan Stanley =
reserves the right, to the extent permitted under applicable law, to =
monitor electronic communications. This message is subject to terms =
available at the following link: </FONT><A =
HREF=3D"http://www.morganstanley.com/disclaimers"><FONT =
COLOR=3D"#808080" =
SIZE=3D"1">http://www.morganstanley.com/disclaimers</FONT></A><FONT =
COLOR=3D"#808080" SIZE=3D"1">. If you cannot access these links, please =
notify us by reply message and we will send the contents to you. By =
messaging with Morgan Stanley you consent to the =
foregoing.</FONT></FONT></FONT></SPAN></FONT></SPAN></DIV><FONT =
SIZE=3D"+0"></FONT><FONT SIZE=3D"+0"></FONT><FONT =
SIZE=3D"+0"></FONT><SPAN></SPAN><FONT =
SIZE=3D"+0"></FONT><SPAN></SPAN></BODY></HTML>
--_000_F685237642C8674A99FCFE0F4A4A217B07D5E201OYWEX0202N3msad_--