#34918: Assigning model instance to `_id`/attname field saves correctly, but 
breaks
accessing the field
-------------------------------------+-------------------------------------
               Reporter:  ricardo-   |          Owner:  nobody
  passthrough                        |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  4.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Model definition:

 {{{#!python
 class Author(models.Model):
     id = models.UUIDField(primary_key=True, default=uuid.uuid4,
 editable=False)

 class Book(models.Model):
     id = models.UUIDField(primary_key=True, default=uuid.uuid4,
 editable=False)
     author = models.ForeignKey(
         Author, null=True, blank=True, on_delete=models.CASCADE
     )
 }}}

 {{{#!python
 In [1]: book = Book.objects.create()

 In [2]: author = Author.objects.create()

 In [3]: book.author_id

 In [4]: book.author

 In [5]: book.author_id = author

 In [6]: book.save()

 In [7]: book.author
 ---------------------------------------------------------------------------
 KeyError                                  Traceback (most recent call
 last)
 ...
 ValidationError: ['“Author object (caaf8f9a-f934-44e9-8e6b-00d71d116acf)”
 is not a valid UUID.']
 }}}

 Similarly, if someone tries to use `book.author_id` to fetch an author
 using `Author.objects.get(id=book.author_id)` will also fail with a
 similar error.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34918>
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/0107018b4d61c315-8996e494-51e4-4dee-9921-f05776293ab7-000000%40eu-central-1.amazonses.com.

Reply via email to