-
-
Notifications
You must be signed in to change notification settings - Fork 291
Replace deepcopy of the Q object #543
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
base: master
Are you sure you want to change the base?
Conversation
Still trying to run unit tests locally, hoping marking this PR as ready would trigger some on project side. |
See #542 |
ebf9c4d
to
8199c3d
Compare
Can also confirm that is indeed fixing the issue in deepcopying Q objects. (reproduced on Python 3.7) |
Is there some unittest can cover the case it fixes? |
I think if the existing unit tests work, that is sufficient, since it shows the change doesn't break from the current method of copying. We could assign a non picklable object attr to one of the children to prevent future regression? |
+1 to adding a non picklable object attr to prevent future regressions or even an explicit scenario that should break in 3.7 without this fix |
@AdamDonna It's been a while -- I came back to try to add a test. The test is successful, and it fails if I swap deepcopy back in. I'm not happy with the test data, but I could not figure out how to trigger the code path into django's trees.py. Can we accept this PR so I can eventually remove my patch from my project? (Also the pre commit failures look pre-existing..) |
I am wondering, though, if this code is ok:
Yes, tuples are immutable.... but what they contain are not necessarilly, if, say it contained a dict. |
Q() derives from tree.Node, which adds copy in Django 4.2+, and does this (from django source):
Let's jump into the debugger and see what happens.
Step past q.copy() and we get:
Are these objects actually deep copied in django's copy()? No. both the tuple and the Model are just references to the original. So my implementation for Django < 4.2 doesn't do anything different, IMHO.
|
There is one oddity, though, that I've highlighted in my latest push. Django's copy seems to change the case of some of the Q() parameters. See the comment in the code for more info. |
No description provided.