#33586: Cannot delete object (A) referenced by another object (B) if said object
(A) has a foreign key to a custom user.
-------------------------------+------------------------------------
     Reporter:  Jeremy Poulin  |                    Owner:  Bhuvnesh
         Type:  Bug            |                   Status:  assigned
    Component:  Migrations     |                  Version:  4.0
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+------------------------------------

Comment (by Bhuvnesh):

 you were right, the problem was inside {{{RunPython.state_forwards}}} as
 it is not mutating any state . but it looks like like we need to reload
 apps cache before running backwards migration after forward migration.
 {{{
 def state_forwards(self, app_label, state):
         # RunPython objects have no state effect. To add some, combine
 this
         # with SeparateDatabaseAndState.
         pass
 }}}

 one thing we can do is re-creating the apps inside
 {{{database_backwards}}} for RunPython Operation. This should also not
 affect the performance much.
 {{{ #!patch
 diff --git a/django/db/migrations/operations/special.py
 b/django/db/migrations/operations/special.py
 index 94a6ec72de..835f2c7017 100644
 --- a/django/db/migrations/operations/special.py
 +++ b/django/db/migrations/operations/special.py
 @@ -193,6 +193,7 @@ class RunPython(Operation):
              self.code(from_state.apps, schema_editor)

      def database_backwards(self, app_label, schema_editor, from_state,
 to_state):
 +        from_state.__dict__.pop('apps', None)
          if self.reverse_code is None:
              raise NotImplementedError("You cannot reverse this
 operation")
          if router.allow_migrate(
 }}}
 we could've done the same thing inside {{{RunPython.state_forwards}}} but
 since reloading apps is not required for forward migrations, we can save
 some time there.

 Ps: Passing all tests.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33586#comment:16>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018364b8323f-215bf009-c303-4bad-8b17-f27d731ea6a5-000000%40eu-central-1.amazonses.com.

Reply via email to