Curious: SAWarning: DELETE statement on table '…' expected to delete 1 row(s); 0 were matched.

2,041 views
Skip to first unread message

jens.t...@gmail.com

unread,
Oct 26, 2017, 6:32:10 AM10/26/17
to sqlalchemy
Hi,

I am curious about this warning:

/…/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py:964: SAWarning: DELETE statement on table '…' expected to delete 1 row(s); 0 were matched.  Please set confirm_deleted_rows=False within the mapper configuration to prevent this warning.
  (table.description, expected, rows_matched)

I found this Stackoverflow thread but it didn't give away mach information.

The warning appears seemingly random, and I'm curious about its details. Could somebody please shed light on it? I'm hesitant about silencing a warning without understanding its cause(s).

Thank you!
Jens

Mike Bayer

unread,
Oct 26, 2017, 9:24:54 AM10/26/17
to sqlal...@googlegroups.com
On Thu, Oct 26, 2017 at 6:32 AM, <jens.t...@gmail.com> wrote:
> Hi,
>
> I am curious about this warning:
>
> /…/lib/python3.5/site-packages/sqlalchemy/orm/persistence.py:964: SAWarning:
> DELETE statement on table '…' expected to delete 1 row(s); 0 were matched.
> Please set confirm_deleted_rows=False within the mapper configuration to
> prevent this warning.
> (table.description, expected, rows_matched)

it means the ORM emitted a statement like:

DELETE FROM your_table WHERE primary_key=<X>

and then there was no row with "X". This is not supposed to happen,
and is usually an indicator that ORM-level code is causing a delete of
the same row more than once. Such as, emitting a DELETE statement
and then also saying session.delete(some_object). You'd want to
understand why this is happening and then if you identify it as an
unavoidable situation, set up that flag.



>
> I found this Stackoverflow thread but it didn't give away mach information.
>
> The warning appears seemingly random, and I'm curious about its details.
> Could somebody please shed light on it? I'm hesitant about silencing a
> warning without understanding its cause(s).
>
> Thank you!
> Jens
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+...@googlegroups.com.
> To post to this group, send email to sqlal...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

jens.t...@gmail.com

unread,
Oct 26, 2017, 4:13:19 PM10/26/17
to sqlalchemy
Thanks Mike!

My code actually only uses session.delete(obj), at no place does it issue statements directly. Since this is running in the context of requests for a web server (as per this Pyramid cookiecutter), could it be that two requests attempt to delete the same resource, with one succeeding and the other not?

Cheers,
Jens

Mike Bayer

unread,
Oct 26, 2017, 4:30:25 PM10/26/17
to sqlal...@googlegroups.com
On Thu, Oct 26, 2017 at 4:13 PM, <jens.t...@gmail.com> wrote:
> Thanks Mike!
>
> My code actually only uses session.delete(obj), at no place does it issue
> statements directly. Since this is running in the context of requests for a
> web server (as per this Pyramid cookiecutter), could it be that two requests
> attempt to delete the same resource, with one succeeding and the other not?

it does serve as a rudimentary concurrency check if you are using
isolation below repeatable read, so depending on specifics yes that
could be happening as well.

>
> Cheers,
> Jens
>
>
> On Thursday, October 26, 2017 at 11:24:54 PM UTC+10, Mike Bayer wrote:
>>
>>
>> it means the ORM emitted a statement like:
>>
>> DELETE FROM your_table WHERE primary_key=<X>
>>
>> and then there was no row with "X". This is not supposed to happen,
>> and is usually an indicator that ORM-level code is causing a delete of
>> the same row more than once. Such as, emitting a DELETE statement
>> and then also saying session.delete(some_object). You'd want to
>> understand why this is happening and then if you identify it as an
>> unavoidable situation, set up that flag.
>>
>>
Reply all
Reply to author
Forward
0 new messages