This project is archived and is in readonly mode.
DataError when underlying type changes
-
Daniele Varrazzo
- State changed from new to invalid
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.
-
Chad Whitacre
Thanks @dvarrazzo. Scoping our
register_compositecalls to the connection or cursor would narrow the race condition, but wouldn't eliminate it. I'm not sure we can eliminate it, though, so what would you think of raising a subclass ofDataErrorinCompositeCaster.parseinstead ofDataErroritself? That way our application could catch that (without swallowing other, unrelatedDataErrors) and then retryregister_compositeor take other measures. Would this be acceptable to you? -
Daniele Varrazzo
Hello Chad,
the use case for such subclass is fairly restricted, and I think it would be more the hassle to document it than its general usefulness, not to mention that people is usually unhappy to get a new feature in rel. 2.5.2.
So my suggestion is you make your own subclass of the adapter, which should be something as easy as (untested):
class CompositeChanged(DataError): pass class OurCompositeCaster(CompositeCaster): def parse(self, s, curs): try: return super(OurCompositeCaster, self).parse(s, curs) except DataError, e: raise CompositeChanged(str(e))this should do everything you need.
-
Chad Whitacre
Sounds sensible. Thanks Daniele! :-)