zopefoundation / zope.sqlalchemy

Integration of SQLAlchemy with transaction management
Other
32 stars 34 forks source link

`psycopg.errors.OperationalError.sqlstate` can be `None` #81

Closed Daverball closed 1 year ago

Daverball commented 1 year ago

A small bug with the new psycopg 3 backend has reared its head in production, apparently sqlstate can be None for certain rare client side exceptions (e.g. server closed connection unexpectedly), so the following check needs to be modified in order to be completely safe:

https://github.com/zopefoundation/zope.sqlalchemy/blob/758572997a128a25658385655e45d6e6de963f10/src/zope/sqlalchemy/datamanager.py#L48

The lambda should be changed to: lambda e: e.sqlstate and e.sqlstate.startswith('40'))

@icemac Considering this is such a small change I hope you can just quickly do it yourself, thanks!

icemac commented 1 year ago

@Daverball See #82 for a PR. Do you think it is okay?

Daverball commented 1 year ago

@icemac Looks good to me, thanks!

icemac commented 1 year ago

I just released the fix as https://pypi.org/project/zope.sqlalchemy/3.1/