Skip to content

Refs #29253 -- Fixed method_decorator() crash if decorator sets a new attribute. #10091

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 1 commit into from
Jun 27, 2018

Conversation

cjerdonek
Copy link
Contributor

This fixes a regression stated in PR #9819 in this comment:
#9819 (comment)

# a function because one can't set new attributes on bound method
# objects -- only functions.
def bound_method(*args2, **kwargs2):
return method.__get__(self, type(self))(*args2, **kwargs2)
Copy link
Member

Choose a reason for hiding this comment

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

Would functools.partial work here?

from functools import partial
bound_method = partial(method.__get__(self, type(self)))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to work (the decorator tests passed locally), which surprised me. Thanks! The use of def bound_method(*args2, **kwargs2) I restored from Django's code base prior to my change, but it wasn't clear it was needed since the tests passed without it (but with this PR it's now covered by the tests).

"""
Test transaction.non_atomic_requests().
"""
import django.db.transaction as transaction
Copy link
Member

Choose a reason for hiding this comment

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

Move to the top.

obj = MyClass()
obj.method() # This should not error out.

def test_non_atomic_requests(self):
Copy link
Member

Choose a reason for hiding this comment

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

I don't think both tests are required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove the second one then (the test of transaction.non_atomic_requests()), because the first one is more focused and tests the exact code path that went wrong.

The second one was useful in showing reviewers that the reported regression was actually fixed. I will remove the test after addressing your other review comment so that CI can at least run this test once with your first suggested change.

Copy link
Contributor Author

@cjerdonek cjerdonek left a comment

Choose a reason for hiding this comment

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

I'm addressing the comments soon.

obj = MyClass()
obj.method() # This should not error out.

def test_non_atomic_requests(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove the second one then (the test of transaction.non_atomic_requests()), because the first one is more focused and tests the exact code path that went wrong.

The second one was useful in showing reviewers that the reported regression was actually fixed. I will remove the test after addressing your other review comment so that CI can at least run this test once with your first suggested change.

# a function because one can't set new attributes on bound method
# objects -- only functions.
def bound_method(*args2, **kwargs2):
return method.__get__(self, type(self))(*args2, **kwargs2)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to work (the decorator tests passed locally), which surprised me. Thanks! The use of def bound_method(*args2, **kwargs2) I restored from Django's code base prior to my change, but it wasn't clear it was needed since the tests passed without it (but with this PR it's now covered by the tests).

@cjerdonek
Copy link
Contributor Author

I addressed @charettes's comments.

@timgraham timgraham force-pushed the ticket_29253_regression branch from 258cc8b to b53fc83 Compare June 27, 2018 15:22
@timgraham timgraham changed the title Refs #29253 -- Fixed method_decorator regression. Refs #29253 -- Fixed method_decorator() crash if decorator sets a new attribute. Jun 27, 2018
@timgraham timgraham merged commit f434f5b into django:master Jun 27, 2018
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.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy