Skip to content

Fixes for argument mutations when calling view methods #476

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

Merged
merged 7 commits into from
Nov 17, 2022
Merged

Fixes for argument mutations when calling view methods #476

merged 7 commits into from
Nov 17, 2022

Conversation

stat1c-void
Copy link
Contributor

I was experiencing a problem with Unicorn, so here are some fixes.

Given: a component view method with single argument, type-hinted as a Model.

Problem: consecutive calls to the method with the same arguments would result in successful first call, but exceptions in next calls. Behavior repeats with restart of a worker.

It would seem that parse_call_method_name() output in the lru_cache would later be mutated, resulting in incorrect caching.

P.S. And a few other fixes - I noticed some small problems on the way.

Comments start with "#" or ";", and no inline comments.
See: https://editorconfig-specification.readthedocs.io/
- no more mutation of arguments in _call_method_name()
- fixed broad TypeError except in _call_method_name() - it was shadowing exceptions
- result of parse_call_method_name is now immutable (which ends up in lru_cache)
- updated related tests
@@ -81,10 +83,10 @@ def validate_checksum(self):


class Return:
def __init__(self, method_name, args=[], kwargs={}):
def __init__(self, method_name, args=None, kwargs=None):
Copy link
Owner

Choose a reason for hiding this comment

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

Ugh, thanks for this fix!

@adamghill
Copy link
Owner

Thank you so much for digging into this bug and making this PR. I can't believe I never ran into it while testing. I really appreciate it and will merge it into main as soon as all the tests pass.

@adamghill adamghill merged commit 8047f9a into adamghill:main Nov 17, 2022
@adamghill
Copy link
Owner

@all-contributors add @stat1c-void for code and tests

@allcontributors
Copy link
Contributor

@adamghill

I've put up a pull request to add @stat1c-void! 🎉

@stat1c-void
Copy link
Contributor Author

Nice, cheers!

@stat1c-void stat1c-void deleted the stat1c-void/dev branch November 17, 2022 09:31
@adamghill
Copy link
Owner

I just published 0.49.2 to https://pypi.org/project/django-unicorn/. Thanks again for the fixes. 🦄

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.

2 participants