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

Request for documentation around best practice when running DB queries on Import #573

Open
goetzk opened this issue Jan 31, 2018 · 1 comment

Comments

@goetzk
Copy link

goetzk commented Jan 31, 2018

Hi, I have an upstream which triggers the behaviour described in pytest-dev/pytest#2825 and #499 - they set a constant from a DB query which occurs during import.

I see some comments describing how to defer the query election (in https://stackoverflow.com/questions/43326132/how-to-avoid-import-time-database-access-in-django ) such as https://github.com/ionelmc/python-lazy-object-proxy, but is there a documented best practice on how to defer DB queries so they don't occur during import?
While reading pytest-django/issues/499 @pelme asserts that "Doing database queries at import time comes with a number of problems and should be avoided. Even if your code happens to work in your particular case, supporting this pattern in pytest-django is not feasible." but I can't find any supporting documentation for that assertion either.

Is there a page (or pages) which I can refer upstreams to which answer those questions?

@goetzk
Copy link
Author

goetzk commented Feb 1, 2018

Thought I should mention some of the places I'm seeing the db being accessed

  • In a reports module (in several places) that makes a dict of all available membership types to set a constant, or a dict of objects to set a constant
  • These could be deferred so the queries weren't run on import
  • In a sign up form to check for the relevant pricing for a membership
  • I haven't figured out how to defer this one yet.

There may be others but this is where I've seen so far.

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

No branches or pull requests

1 participant