#33608: select_related() to nullable FK with db_constraint=False do not promote
OUTER joins.
-------------------------------------+-------------------------------------
     Reporter:  Mathieu Hinderyckx   |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  3.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     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 Simon Charette):

 > `Object.objects.filter(remote_object_id=1234).first().remote_object`
 doesn't raise a `DoesNotExist` exception. It returns null, as it should
 be.

 I think you might be wrong here. Did you test this statement? I did with
 Django 3.2.12 and 4.0.3.

 {{{#!diff
 diff --git a/poc/poc_models/tests.py b/poc/poc_models/tests.py
 index 27b8249..f7edb32 100644
 --- a/poc/poc_models/tests.py
 +++ b/poc/poc_models/tests.py
 @@ -10,6 +10,10 @@ def setUpTestData(cls):

      # All of the test methods below try to fetch the same object which
 was created in setUpTestData

 +    def test_access_remote_object_broken_referential_integrity(self):
 +        with self.assertRaises(RemoteObject.DoesNotExist):
 +
 Object.objects.filter(remote_object_id=1234).first().remote_object
 +
      def test_remote_object_does_exist_object_should_be_found(self):
          RemoteObject.objects.create(remote_id=1234)
 }}}

 A `DoesNotExist` **is** raised when accessing `.remote_object` because
 your data breaks integrity expectations that the ORM is built around. If
 you break these integrity expectations you should expect undefined
 behaviour.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33608#comment:6>
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/0107017fe7224bce-0172576a-9ff8-43ef-a65d-f5b815fa6be7-000000%40eu-central-1.amazonses.com.

Reply via email to