Thursday, July 26, 2018

avoiding import-time queries

I'm looking for some best-practice (or at least workable) suggestions for avoiding import-time queries. I have some database records that are constant, and these constants are used all over the application. Is there any way to get those constants out of the database once at startup? 

At present, I am working on a set of apps with a single underlying database. And they wouldn't build at all when I tried to migrate a new test database because of import-time queries, because it wants to validate the references to those constants at build time (and can't, because in this case my new test database has no tables yet). Is there any way to store these model records in something that will persist between builds (kind of like test fixtures)? A StackOverflow discussion suggested the Python Lazy Object Proxy, but that project appears to have been abandoned. The Django docs themselves simply recommend avoiding query-at-import behaviors--I can definitely see it causes all kinds of problems that are not easy to circumvent--but they make no recommendations for alternatives. Is it indeed necessary to keep querying for these all over the app? Is there a third-party solution that I've overlooked?

Django 2.0. Thank you!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9510552d-9afe-47b0-842e-6f80e9a28bbe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment