Opened 9 years ago

Closed 9 years ago

Last modified 9 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 by Tim Graham, 9 years ago

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

Regression in 1.9 bisected to 845817b039fc059955bb1eafa5fd78565a49159d.

comment:2 by Sasha Gaevsky, 9 years ago

Owner: changed from nobody to Sasha Gaevsky
Status: newassigned

in reply to:  1 comment:3 by Sasha Gaevsky, 9 years ago

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 9 years ago by Sasha Gaevsky (previous) (diff)

comment:4 by Tim Graham, 9 years ago

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

in reply to:  4 comment:5 by Sasha Gaevsky, 9 years ago

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 by Tim Graham, 9 years ago

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

comment:7 by Sasha Gaevsky, 9 years ago

Has patch: set

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

Resolution: fixed
Status: assignedclosed

In a839d71d:

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

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

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 by Tim Graham <timograham@…>, 9 years ago

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 by Tim Graham <timograham@…>, 9 years ago

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