Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#25997 closed Bug (fixed)

Editing ForeignKey in admin popup causes incorrect escaping for uuid field

Reported by: Zach Borboa Owned by: Sasha Gaevsky
Component: contrib.admin Version: 1.9
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Editing and saving a model's foreign key causes the related field to display incorrectly.

Displays something like "b71658a1\u002Df845\u002D4a44\u002D8085\u002D03034580ac72"
instead of "b71658a1-f845-4a44-8085-03034580ac72"

Screenshot: https://i.imgur.com/Q5lrfV2.png

Reproduce:

  1. Create new project using python3

$ mkvirtualenv --python=$(which python3) myproject && cd myproject
$ django-admin startproject mysite && cd mysite
$ python manage.py startapp polls

  1. Add polls to INSTALLED_APPS
  1. Set polls/models.py
    import uuid
    from django.db import models
    
    class Question(models.Model):
        id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
        question_text = models.CharField(max_length=200)
    
        def __str__(self):
            return str(self.id)
    
    class Choice(models.Model):
        question = models.ForeignKey(Question)
        choice_text = models.CharField(max_length=200)
    
  1. Set polls/admin.py
    from django.contrib import admin
    
    from .models import Choice
    from .models import Question
    
    admin.site.register(Choice)
    admin.site.register(Question)
    
  1. Go to the admin add page for Choice http://127.0.0.1:8000/admin/polls/choice/add/
  2. Click the plus sign ("+") next to the "Question:" label. Enter question text (like "test") and click save. The uuid is correctly displayed in the Question select box.
  3. Click the pencil edit button next to the Question label. In the new popup window, click save. The uuid is no longer correctly displayed.

Change History (11)

comment:1 Changed 8 years ago by Tim Graham

Component: Uncategorizedcontrib.admin
Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Regression in 1.9 bisected to 845817b039fc059955bb1eafa5fd78565a49159d.

comment:2 Changed 8 years ago by Sasha Gaevsky

Owner: changed from nobody to Sasha Gaevsky
Status: newassigned

comment:3 in reply to:  1 Changed 8 years ago by Sasha Gaevsky

Replying to timgraham:

Regression in 1.9 bisected to 845817b039fc059955bb1eafa5fd78565a49159d.

Just wondering if you tested in master branch because I suspect there could be related issue with UUID field.

Last edited 8 years ago by Sasha Gaevsky (previous) (diff)

comment:4 Changed 8 years ago by Tim Graham

There's another regression when closing the popup on master if that's what you ran into. It's tracked in comment:6:ticket:25165

comment:5 in reply to:  4 Changed 8 years ago by Sasha Gaevsky

Replying to timgraham:

There's another regression when closing the popup on master if that's what you ran into. It's tracked in comment:6:ticket:25165

Yes, that's exactly it.

Will it be fixed in terms of 25165 or new ticket will be opened?

comment:6 Changed 8 years ago by Tim Graham

For now #25165 is reopened to fix the regressions it introduced.

comment:7 Changed 8 years ago by Sasha Gaevsky

Has patch: set

comment:8 Changed 8 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In a839d71d:

[1.9.x] Fixed #25997 -- Removed redundant escaping in admin's edit related model popup.

comment:9 Changed 8 years ago by Tim Graham <timograham@…>

In ade54ff:

Refs #25165 -- Fixed JSON serialization for add/edit popup in the admin.

Forwardport of test in o839d71d8562abe0b245024e55ca1d02a45e58fd from stable/1.9.x
(refs #25997).

comment:10 Changed 8 years ago by Tim Graham <timograham@…>

In 5052f79:

Added a test for adding a UUID pk object using the "Add related" admin popup.

Follow up to refs #25997 but this case wasn't broken.

comment:11 Changed 8 years ago by Tim Graham <timograham@…>

In cb96d0c:

[1.9.x] Added a test for adding a UUID pk object using the "Add related" admin popup.

Follow up to refs #25997 but this case wasn't broken.

Backport of 5052f79df45d843d1e44dcc47152ed503220098f from master

Note: See TracTickets for help on using tickets.
Back to Top