Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't catch pony.orm.core.TransactionIntegrityError #676

Open
thmsklngr opened this issue Jan 26, 2023 · 1 comment
Open

Can't catch pony.orm.core.TransactionIntegrityError #676

thmsklngr opened this issue Jan 26, 2023 · 1 comment

Comments

@thmsklngr
Copy link

thmsklngr commented Jan 26, 2023

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

@erik-megarad
Copy link

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}')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants