Hello Pakal, Making django.setup() idempotent
In https://code.djangoproject.com/ticket/28752 <https://code.djangoproject.com/ticket/28752>, you say: > I've been bitten numerous times by the impredictable behaviour of django when > django.setup() was called numerous times. > In the old days I had exceptions, now it's mainly subtle breakages of logging > configuration. This is fuzzy for a bug report. Ideally, you should say: - What you're doing (minimal reproduction instructions, within supported use of Django) - What results you're expecting - What results you're getting Anyway it suggests that the problem is about logging. In this comment <https://github.com/django/django/pull/11440#pullrequestreview-250231882> I said that the only possible bug is that `configure_logging()` isn't idempotent. Your answer <https://github.com/django/django/pull/11440#issuecomment-504116261> confirms that the issue is really about logging. Let's fix configure_logging(), then! Barring new arguments in favor of the proposed approach, which involves nested locks, I'm -1. Nested locks create a possibility of deadlocks. See my comment on the PR for details. Making django.setup() tweakable Again, the rationale is fuzzy. I'm seeing two use cases: - pytest-django - django-compat-patchers One more or one less monkey patch isn't going to make a difference to these projects ;-) I'm ready to accept that there's a need for projects that aren't big hacks but I need to see it explained clearly and specifically. I'd really like to see a feature request in the form of: - I want to do X, which is a reasonable thing to do and stays within supported use of Django, except I need to override django.setup() - Here's what the code looks like with a workaround (monkey-patching, probably) - Here's what the code would look like with the improvement I'm asking for (hopefully much better) - Here are the alternatives I considered and why I rejected them - Other use cases also include Y and Z I'm asking this because concrete use cases will put us in a better position to find the best solution. Best regards, -- Aymeric. > On 27 Jun 2019, at 23:26, Pkl <chambon.pas...@gmail.com> wrote: > > Hello everyone, > > I'm bringing here, for broader review and discussion, the subject of making > django setup more "tweakable": > https://code.djangoproject.com/ticket/30536 > https://github.com/django/django/pull/11435 > > There is indeed a need for doing pre/post operations at that crucial moment > of the framework lifetime, especially to apply compatibility shims > (greening-related, API stability-related...) and setup test scaffolding, > stubs etc. > > A separate PR has been created to handle threadsafety/idempotence > (https://github.com/django/django/pull/11440) when multiple actors try to > setup django concurrently, but a discussion remains on how to potentially > allow users to specify an alternative setup > > I originally did a POC with a new django setting, but if we want to have full > control, even settings might not be normally loaded at that stage. So maybe, > as apollo13 suggested, an environment variable, like DJANGO_SETUP_CALLABLE, > complementing the DJANGO_SETTINGS_MODULE one? > What are your thoughts about this ? > > thanks, > regards, > Pakal > > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com > <mailto:django-developers+unsubscr...@googlegroups.com>. > To post to this group, send email to django-developers@googlegroups.com > <mailto:django-developers@googlegroups.com>. > Visit this group at https://groups.google.com/group/django-developers > <https://groups.google.com/group/django-developers>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/0206c98c-199f-49f9-9ff7-cba736e71224%40googlegroups.com > > <https://groups.google.com/d/msgid/django-developers/0206c98c-199f-49f9-9ff7-cba736e71224%40googlegroups.com?utm_medium=email&utm_source=footer>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/4673AD3D-4EDF-44FB-931F-B3E231D6311D%40polytechnique.org. For more options, visit https://groups.google.com/d/optout.