Code

Opened 2 years ago

Closed 18 months ago

#17200 closed Bug (fixed)

"View on site" link breaks when quote(object_id) != object_id

Reported by: dchandek Owned by: dlanger
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: dchandek, ldelaveau@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The change_view method of django.contrib.admin.options.ModelAdmin returns object_id as passed in. This means that the "View on site" link breaks in cases where the django.contrib.admin.util.quote(object_id) != object_id.

There are two possible solutions:
1) Call django.contrib.admin.util.unquote() on object_id before returning to change_view template;
2) Call django.contrib.admin.util.unquote() on object_id in django.contrib.contenttypes.views.shortcut in this line: obj = content_type.get_object_for_this_type(pk=object_id).

Attached are svn diffs for each.

Attachments (3)

django.contrib.admin.options.diff (571 bytes) - added by dchandek 2 years ago.
django.contrib.contenttypes.views.diff (1.4 KB) - added by dchandek 2 years ago.
17200-patch-and-test.diff (2.6 KB) - added by dchandek 2 years ago.
Initial attempt at patch + unit test. Note that i18n not applied to "View on site" in test.

Download all attachments as: .zip

Change History (12)

Changed 2 years ago by dchandek

Changed 2 years ago by dchandek

comment:1 Changed 2 years ago by dchandek

  • Cc dchandek added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 follow-up: Changed 2 years ago by julien

  • Component changed from Uncategorized to contrib.admin
  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

Solution 1) is the right one. Could you provide a test case? Thanks!

comment:3 in reply to: ↑ 2 Changed 2 years ago by dchandek

Replying to julien:

Solution 1) is the right one. Could you provide a test case? Thanks!

Happy to take a crack at a test case. Since I've not contributed one to Django before, I'm not sure the more helpful way to do this. My first guess is to write a test_viewonsite_link method in the AdminViewStringPrimaryKeyTest class of tests/regressiontests/admin_views/tests.py.

Changed 2 years ago by dchandek

Initial attempt at patch + unit test. Note that i18n not applied to "View on site" in test.

comment:4 Changed 2 years ago by dchandek

I realized that the new test could just be added to the test_get_change_view() method. As noted, i18n may need to be applied to "View on site" text in test.

comment:5 Changed 22 months ago by claudep

  • Needs tests unset

comment:6 Changed 22 months ago by claudep

I guess that this issue might have been fixed along #18444. Can someone confirm?

comment:7 Changed 20 months ago by dlanger

  • Owner changed from nobody to dlanger
  • Status changed from new to assigned

comment:8 Changed 18 months ago by vicould

  • Cc ldelaveau@… added

I have the feeling that the test test_shortcut_view_with_escaping at line 1453 in tests/regressiontests/admin_views/tests.py confirms that the issue is fixed:

def test_shortcut_view_with_escaping(self):                                                              
    "'View on site should' work properly with char fields"                                               
    model = ModelWithStringPrimaryKey(pk='abc_123')                                                      
    model.save()                                                                                         
    response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(model.pk))                                                                                                        
    should_contain = '/%s/" class="viewsitelink">' % model.pk                                            
    self.assertContains(response, should_contain)                                                        

comment:9 Changed 18 months ago by claudep

  • Resolution set to fixed
  • Status changed from assigned to closed

OK, let's consider it fixed.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.