pony icon indicating copy to clipboard operation
pony copied to clipboard

Can't catch pony.orm.core.TransactionIntegrityError

Open thmsklngr opened this issue 2 years ago • 1 comments

Hi,

I'm currently out of any idea. I have some issues with external data, which is not so dramatic for my data I want, but it causes a TransactionIntegrityError and I can't catch it, regardless whatever I do.

Example:

try:
    MyModel(value1=value1, value2=value2)
except pony.orm.core.TransactionIntegrityError as exc:
    print(f'Error: {exc}')
else:
    db.flush()
    db.commit()

From my point of view this syntax is correct, however, the exception is thrown anyway, it's not caught by the try/except block. I also exchanged pony.orm.core.TransactionIntegrityError with Exception for more general purpose, no effect.

Am I doing something wrong or what may be the reason?

Many thanks in advance, regards, Thomas

thmsklngr avatar Jan 26 '23 18:01 thmsklngr

Is the exception being raised from inside the else block? Try this

try:
    MyModel(value1=value1, value2=value2)
    db.flush()
    db.commit()
except pony.orm.core.TransactionIntegrityError as exc:
    print(f'Error: {exc}')

erik-megarad avatar Apr 04 '23 17:04 erik-megarad