Skip to content

Conversation

@aangelinali
Copy link
Contributor

Key Change

  • Added @wraps(func) to record_api_function and record_function methods

Explanation for Error
When implementing analytics on Penn Clubs, the following error was thrown.

AssertionError: Expected function (wrapped_func) to match its attribute name (email_blast)

  • The reason for this error is that in a ViewSet, Django finds custom endpoints with @action. After inspecting each extra action, Django asserts that the callable's name matches the attribute name on the class. But, the analytics decorator (as it currently is written) returns a wrapper named wrapped_func and raised the error.

Explanation for Fix

  • Adding @wraps(func) to the inner wrapper in both functions preserves the original function's metadata (notably, name in this case).
  • The reason this error was not encountered when implementing Penn Mobile analytics since Penn Mobile uses APIView / ListAPIView classes. Django does not check the callable's name for APIView methods so the fact that the decorator returns wrapped_func does not raise an error.

@aangelinali aangelinali requested a review from dr-Jess September 17, 2025 23:22
Copy link
Collaborator

@dr-Jess dr-Jess left a comment

Choose a reason for hiding this comment

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

Will approve after small nit is fixed so that ci/cd works.

@aangelinali aangelinali requested a review from dr-Jess September 18, 2025 18:57
Copy link
Collaborator

@dr-Jess dr-Jess left a comment

Choose a reason for hiding this comment

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

lgtm

@esinx esinx merged commit 4a993e6 into master Sep 19, 2025
3 checks passed
@esinx esinx deleted the angelina/decorator-fix branch September 19, 2025 21:07
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