-
Notifications
You must be signed in to change notification settings - Fork 231
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
Use of ObjectProxy with type() #241
Comments
Is your code online on GitHub somewhere so can see the rest of the code you have for your derived ObjectProxy? Also how that is used would be helpful as well. It is too hard from just this code snippet to understand what you are trying to do. |
Not on GitHub, but hopefully this will suffice. If you have a MSSQL database handy, change the database name and the URL and this should be runnable.
This is the exception thrown (top of exception stack): |
You are probably better off monkey patching the connection object instance because Monkey patching The following messy code should work though if adapted:
It relies on overriding the I don't recollect ever seeing anything ever modify the Anyway, summary is that SQLAlchemy is not friendly to using proxy objects. It could be argued that it's |
BTW, doing it this way you don't actually need
|
Hmmm, wrapt doesn't specifically prohibit updating |
Okay, so the pure Python implementation of |
Nope, should be easy. I just don't provide a setter. Anyway, fixing that will still not help in this case. |
Thank you for the suggestions. I ended up using the version without |
I didn't know it had to be on the type either. I tried monkey patching the instance first as well. :-( So have no real idea why it is that way. |
Looking up magic methods like The reason is probably performance: remember that in the C implementation, Python classes/types have dedicated fields ("slots") in their C struct for many (all?) of the dunder methods. If you always look up dunder methods on the type, then looking up f.e. This kind of optimization for common operations would be very consistent with other decisions made in Python: for example, in the past Guido rejected adding operator overloads on |
This is a question (not an issue).
I am using
wrapt.ObjectProxy
to modify context manager behavior (__enter__
,__exit__
) of a database connection object (SqlAlchemy Connection). It works as expected with the SqlAlchemy version 1.3.x, but in 1.4.47 it raises an exception in this piece of code (inspection.py, the comments are mine):Is there a workaround for this? Thank you.
The text was updated successfully, but these errors were encountered: