-
Notifications
You must be signed in to change notification settings - Fork 23
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
Applied Schema Caching Fix | Canidate V0.7.1 #121
Conversation
commit 2086167 Merge: d13f7eb 91e1a19 Author: Kashif Iftikhar <[email protected]> Date: Sat Nov 19 12:26:40 2022 +0500 Merge pull request threatify#117 from anthony-poddubny/feature/add_full_count_support Add full count support to the Query commit 91e1a19 Author: Anthony Poddubny <[email protected]> Date: Sat Nov 19 00:08:11 2022 +0200 add full count support commit d13f7eb Merge: 8de2c46 84acdd3 Author: Kashif Iftikhar <[email protected]> Date: Fri Jun 10 14:39:36 2022 +0500 Merge pull request threatify#110 from valentingregoire/patch-1 fix: Typo in README fixed. commit 84acdd3 Author: Valentin Grégoire <[email protected]> Date: Wed Jun 8 09:23:43 2022 +0200 fix: Typo in README fixed. commit 8de2c46 Merge: 641c2cf 202d4e7 Author: Kashif Iftikhar <[email protected]> Date: Thu Apr 21 10:45:50 2022 +0500 Merge pull request threatify#108 from SoundsSerious/fix_mem_schema Added Conditional Checking Of Marshmallow Fields
- use python `__{class}` double underscore behavior to prevent subclassing issues. - added recache option in schema to allow changing schema [ schema(...,recache:bool=False) ]
Thank you for the contribution. I belive you tested the solution but i have some doubts about double underscore properties.
Double score properties is not defined in class. This is the cause of the issue i reported about class inheritation
Thank you for reporting me the solution where i can use CollectionBase, but doesn't fix the issue because _load method from collection is still used and is buggy.
This solution allow schema cache, A.schema() is called twice but not generated twice. simple and clean |
@overbost You will see that I am using the same hasattr/setattr approach with The name mangling approach is purely to apply to the conventions of python. It would be great if you could checkout this code and evaluate the code in this commit since there are additional factors for partial schema instantiation with the I have edited the text of the PR to reflect this |
setattr is a nice workaroud, i have tested your PR and it works.
of course is not causing issues and the waste memory is not too much, but is technically incorrect. |
@overbost This is an interesting example. I have not observed this behavior, checking the I suspect this has to do with accessing any subclass property? Ie. any subclass can access its parent class variables? How would the solution you're proposing handle this differently? I don't think this affects memory at all since the variable from the parent class is defined in the parent class dict. Also good to remember that the point of this schema caching is reduce memory consumption. Every time schema() is called a new set of marshmallow objects is created creating a pretty significant bloat per object which affects CPU as well |
If you check my first comment here there are the code example of the issue and my proposal of solution. I tryed the solution of settattr you use, but there aren't benefit in class inheritance
|
I think these are essentially the same solution. Yours has a dynamic flag, whereas mine has a dynamic variable. The authoritative schema comes from the schema() call so in the end, it's all the same. I agree schema should be static at run time, but it's not a stated requirement in the library. The reason I added the regeneration ability was to address one potential issue causing #114, which caused a revert of There were some issues with the entire concept of schema caching, so I am more concerned about those. I am also concerned about not having it, ie, memory leaks, as per issue #105. I think it might take some time to figure this out but with @kashifpk's input and yours, I'm sure we can determine a solution :) |
@volodymyrko We are discussing the schema caching issue as it relates to a number of issues including one opened by you #114 Its unclear the steps needed to reproduce this error, would you be able to test this PR or let us know how to setup to test for your issue? |
this is the code from README and two asserts to reproduce the issue
the order of assert is important ! if you swap them than the error will disappear (but still it is not correct behavior ). |
I've tested PR in terms of the issue I faced - everything seems to be fine. |
@volodymyrko Awesome this is great! I think this shows that the class name-based lazy caching can handle edge cases like relationship instantiation. @kashifpk any other concerns you think this PR might present? |
@SoundsSerious @overbost @volodymyrko - Thank you for all the work on this. Let me go through this one and #122. I'll report back here. Just want to test out a few scenarios with both approaches. |
@kashifpk would you like me to close out this PR since the other PR effectively supports the same features? |
@SoundsSerious - sure, I couldn't find time to look into other caching PRs, I leave it to your best judgement. |
__{class.__name__}
prefix to store schema caches similar to the python double underscore, name mangling approach.This PR should address these issues, while preserving the memory overflow fix of 0.7.0
#120
#115
#114
@kashifpk I did run these through the testing system and found that all tests passed. I think it might be worthwhile to check the relation's schema since I don't really use those in my application.
@overbost you may find this useful for your issues.