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: bad appmaps in django oscar #346

Closed
wants to merge 1 commit into from

Conversation

zermelo-wisen
Copy link
Collaborator

@zermelo-wisen zermelo-wisen commented Jul 2, 2024

  • Modifies Django Middleware to work when there is no headers attribute in the response, but there is a _headers attribute instead. This issue was observed while running Django Oscar tests with AppMap Python on a specific version (git commit hash: 9574ce2a56f3d99836c2e20785c116da12af6c42) of Django Oscar.
  • Adds a test to ensure that Middleware.__call__ works when get_response returns a response with a _headers attribute instead of headers.

@zermelo-wisen zermelo-wisen force-pushed the fix/bad-appmaps-in-django-oscar branch 4 times, most recently from 2279c1d to 0f0a085 Compare July 2, 2024 17:34
@zermelo-wisen zermelo-wisen marked this pull request as ready for review July 2, 2024 17:48
@zermelo-wisen zermelo-wisen force-pushed the fix/bad-appmaps-in-django-oscar branch from 0f0a085 to ec6fe60 Compare July 3, 2024 09:37
@@ -81,6 +81,23 @@ def __exit__(self, exc_type, exc_value, tb):
return False


def check_call_return_stack_order(events):
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't want to do this in the agent. AppMaps can be quite large, and this will have a significant performance impact. Detecting the problem during fingerprinting is good enough

Copy link
Collaborator Author

@zermelo-wisen zermelo-wisen Jul 7, 2024

Choose a reason for hiding this comment

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

I removed this commit.

(My reasoning was that it would have an overhead but this overhead would always come with the main overhead of creating large AppMaps and it would be relatively small compared to the large AppMap creation itself.)

# django-oscar commit hash: 9574ce2a56f3d99836c2e20785c116da12af6c42
#  example test: tests/functional/dashboard/test_dashboard.py
# TestDashboardIndexForAnonUser::test_is_not_available
headers = getattr(response, 'headers', getattr(response, '_headers', None))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does trying to use headers instead of _headers cause the event-ordering problem?

Copy link
Collaborator Author

@zermelo-wisen zermelo-wisen Jul 7, 2024

Choose a reason for hiding this comment

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

While running a django-oscar test, here "AttributeError: 'HttpResponseRedirect' object has no attribute 'headers'" is raised in our code. pytest framework catches it and marks the test as a failed test. We are able to write an AppMap for the failed test after the failed test finishes, as usual. However, our code which creates the http response return event does not get a chance to run because of this exception. This produces a bad AppMap with an http request call event missing a matching http response return event.

    - Modifies Django Middleware to work when there is no 'headers'
      attribute in the response, but there is a '_headers' attribute
      instead.
      This issue was observed while running Django Oscar
      tests with AppMap Python on a specific version (git commit hash:
      9574ce2a56f3d99836c2e20785c116da12af6c42) of Django Oscar.

    - Adds a test to ensure that Middleware.__call__ works when
      get_response returns a response with a '_headers' attribute
      instead of 'headers.'
@zermelo-wisen zermelo-wisen force-pushed the fix/bad-appmaps-in-django-oscar branch from ec6fe60 to c13cd0c Compare July 7, 2024 09:32
@dustinbyrne dustinbyrne deleted the fix/bad-appmaps-in-django-oscar branch July 16, 2024 13:08
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.

3 participants