Skip to content

Move named url init out of Middleware init#15085

Merged
chrismeyersfsu merged 1 commit into
ansible:develfrom
chrismeyersfsu:fix-named-urls-testable
Apr 10, 2024
Merged

Move named url init out of Middleware init#15085
chrismeyersfsu merged 1 commit into
ansible:develfrom
chrismeyersfsu:fix-named-urls-testable

Conversation

@chrismeyersfsu

Copy link
Copy Markdown
Member
SUMMARY
  • Middleware classes can be instantiated multiple times in testing. To make this a non-issue, move the init code for named urls out of the middleware init and into the app init.
  • This makes it easier to use other testing facilities, like LiveServerTestCase, without having to mock the named url middleware init.
ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • API
AWX VERSION
devel
ADDITIONAL INFORMATION



def _dfs(configuration, model, graph, dead_ends, new_deadends, parents):
from django.contrib.contenttypes.models import ContentType

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

named_url_graph.py is now imported and used in the app ready path. This is a bootstrapping phase and like any bootstrapping phase all the facilities aren't initialized. We have to be careful of what we import and when.

Delays this import.



def _customize_graph():
from django.contrib.auth.models import User

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Delay User import.

@chrismeyersfsu chrismeyersfsu enabled auto-merge (rebase) April 10, 2024 19:28
* Middleware classes can be instantiated multiple times in testing. To
  make this a non-issue, move the init code for named urls out of the
  middleware init and into the app init.
* This makes it easier to use other testing facilities, like
  LiveServerTestCase, without having to mock the named url middleware
  init.
@chrismeyersfsu chrismeyersfsu force-pushed the fix-named-urls-testable branch from 46bc5a0 to 956af4a Compare April 10, 2024 19:28
@chrismeyersfsu chrismeyersfsu merged commit 61ec03e into ansible:devel Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants