title: What does Django DEBUG do under the hood?
body: <p>I have a bug that does not occur when DEBUG is True, whether in production on Apache or locally on the Django dev server. This leads me to ask: What is all the magic that Django DEBUG does behind the scenes? The <a href="https://docs.djangoproject.com/en/3.0/ref/settings/#debug" rel="nofollow noreferrer">documentation</a> doesn't have very much information about this.</p>
  
  <p>Now for the bug. I understand that the following description is too bare-bones for anyone to reproduce, but I have IP to protect, and I don't have much hope of the error being reproduced anyway.</p>
  
  <p>Suppose I have a Django project with at least two apps, app alice with model A and app bob with model B.</p>
  
  <p>I am using UpdateWithInlinesView from django-extra-views. The error occurs when this view constructs a formset from instances of model A. In my email about the server error, I get a message like this:</p>
  
  <p>FieldError at /some/url/
  Cannot resolve keyword 'field_of_A' into field. Choices are: field_of_B_1, field_of_B_2, field_of_B_3</p>
  
  <p>I've gotten this type of error before. It normally happens when you tell a form "I'm using model C" and "I'm using a field called debbie" and model C doesn't have a field called debbie. That part makes sense. But this error makes it look like it's checking against the field names of model B when it should be checking model A. I have been racking my brain trying to figure out how in the world the construction of a form from one model would consult a different model from a different app.</p>
  
  <p>Furthermore, this doesn't happen most of the time, it goes away on server restart, and it doesn't happen under DEBUG = True. So I'm wondering if it's an app registry issue, some sort of race condition that gets the registry out of whack. If so, then I might get somewhere by either understanding the app registry better or understanding what DEBUG does.</p>