Skip to content
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

Fix plone.memoize.view to support unhashable types in function arguments #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thet
Copy link
Member

@thet thet commented Jul 6, 2023

Fixes: #36

@mister-roboto
Copy link

@thet thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@thet
Copy link
Member Author

thet commented Jul 6, 2023

@jenkins-plone-org please run jobs

Copy link
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks memoization of anything that is hashable but not JSON-serializable

@thet thet force-pushed the fix-hashable-arguments branch from 8fbaaf1 to 4e9cea7 Compare July 6, 2023 15:40
@thet
Copy link
Member Author

thet commented Jul 6, 2023

@davisagli a function is such a hashable but non-JSON serializable type... Is this a relevant example? Are there other types which would fail with my fix?

@davisagli
Copy link
Member

@thet a datetime...any data that is not supported by the default json serializer.

I think it'd be wiser to add handling for some specific types like list and dict (i.e. convert to tuple and use dict.items()) rather than use the json module. Even then there are edge cases to consider, like whether 2 dicts in different order should be considered equal, etc...

Copy link

@icemac icemac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not a general fix as it introduces a new regression.

args[1:],
frozenset(kwargs.items()),
json.dumps(args[1:]),
json.dumps(kwargs),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this change allows unhashable types it prevents using types which are not JSON serialisable, like datetime.date. So this change might break existing code.

@thet
Copy link
Member Author

thet commented Jul 7, 2023

@davisagli @icemac tnx for the reviews! Yes, existing code must not be broken. I'll provide an improved version of this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot handle unhashable types in function arguments
4 participants