#36370: Model.objects.get() with a None char parameter intermittently doesn't
retrieve row correctly
-------------------------------------+-------------------------------------
     Reporter:  Marco Antonio Mauro  |                    Owner:  (none)
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  5.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

 * resolution:   => invalid
 * status:  new => closed

Comment:

 Hello Marco Antonio Mauro, thank you for taking the time to create this
 report. I have simplified your example and created a test to try to
 reproduce what you are getting:
 {{{#!python
 class Bar(models.Model):
     id = models.BigAutoField(primary_key=True)
     origin = models.CharField(max_length=1, blank=True, null=True)


 class Foo(models.Model):
     id = models.OneToOneField('Bar', models.DO_NOTHING, db_column='id',
 primary_key=True)
     origin = models.CharField(max_length=1, blank=True, null=True)
 }}}
 The following test never fails for me (the `assertIsNotNone` could be
 removed):
 {{{#!python
 class Ticket36370TestCase(TestCase):

     def test_try(self):
         from .models import Bar, Foo
         bar, _ = Bar.objects.get_or_create(origin='a')
         origin = None # may be a str with something in, an empty str or
 None

         for i in range(10):
             with self.subTest(i=i):
                 try:
                     foo = Foo.objects.get(id=bar, origin=origin)
                 except Foo.DoesNotExist:
                     foo = Foo(id=bar, origin=origin)

                 foo.save()
                 self.assertIsNotNone(foo)
                 foo_db = Foo.objects.get(id=bar, origin=origin)
                 self.assertIsNotNone(foo_db)
 }}}

 I'm guessing you may have other code or dependency in place that may
 affect your runs? Are you using threads or some form of concurrent
 execution?

 Because of the above, I think this report seems better suited to be a
 support request. The best place to get answers to your issue is using any
 of the user support channels from
 [https://docs.djangoproject.com/en/dev/faq/help/#how-do-i-do-x-why-
 doesn-t-y-work-where-can-i-go-to-get-help this link].

 Since the goal of this issue tracker is to track issues about Django
 itself, and your issue seems, at first, to be located in your custom code,
 I'll be closing this ticket as invalid following the
 [https://docs.djangoproject.com/en/dev/internals/contributing/triaging-
 tickets/#closing-tickets ticket triaging process]. If, after debugging,
 you find out that this is indeed a bug in Django, please re-open with the
 specific details and please be sure to include a small Django project to
 reproduce or a failing test case.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36370#comment:1>
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 visit 
https://groups.google.com/d/msgid/django-updates/01070196a6dde9e9-c723cd55-2a7b-4718-83ab-dd24b8634304-000000%40eu-central-1.amazonses.com.

Reply via email to