I can show you where I did something like this for Openstack, which
you can use yourself but you need to extricate it from oslo.db, at the
very least you can grab the regular expressions right out, if you
don't want to use the whole @filters framework:

https://github.com/openstack/oslo.db/blob/master/oslo_db/sqlalchemy/exc_filters.py#L192

On Tue, Mar 20, 2018 at 3:00 PM, Jonathan Vanasco <jvana...@gmail.com> wrote:
> Mike will probably chime in with a more correct answer, but...
>
> You should be able to figure that out by catching the
> `sqlalchemy.exc.IntegrityError` error and inspecting the attributes
> (original error or the text message).
>
>
> http://docs.sqlalchemy.org/en/latest/core/exceptions.html#sqlalchemy.exc.IntegrityError
>
> The DBAPI only defines IntegrityError, and IIRC not all backends provide a
> differentiation between the types of integrity error.
>
>
> On Tuesday, March 20, 2018 at 2:11:44 PM UTC-4, Peter Lai wrote:
>>
>> I'm implementing a recursive upsert operation for an object whose primary
>> key also contains a foreignkey, and I'd like to get some more info from
>> IntegrityError, namely whether integrity was violated because the foreignkey
>> didn't exist (yet) or I am trying to insert a duplicate pkey. In the former
>> case, I'd go and insert the parent, in the latter, I'd just ignore it and
>> rollback (since the state is already end state)
>>
>> Is there a way to fish this out from IntegrityError or do I need to catch
>> DBAPI exceptions instead?
>>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to