Skip to content

eliminate race condition when updating types #26

@chadwhitacre

Description

@chadwhitacre

We ran into an issue over on gratipay/gratipay.com#1583 in that psycopg2 caches information about composite types, so if you alter the type in the database then the cache becomes stale, and the next time you request a record of the composite type, you get a DataError. From @dvarrazzo:

The composite cache is local to where register_composite was called (globally, the connection, or the cursor). You can avoid the problem using it in a restricted scope (e.g. on a cursor, and dropping the cursor after the type is changed). Alternatively just rerun register_composite with the same arguments after changing the type.

And over on http://psycopg.lighthouseapp.com/projects/62710/tickets/183:

Caching of the attribute is necessary but it's local to the scope you have registered the composite.
Avoid using register_composite with global=True: use it on the connection or on the cursor, and dispose the connection or the cursor after the data type is changed. Alternatively just call register_composite again.

How do we eliminate this race condition?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions