Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Error in history view of object with forward slash in primary key #1297

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

muneeb706
Copy link
Member

@muneeb706 muneeb706 commented Jan 24, 2024

  • Used quote method to convert a primary key value into a string that can be used in a URL for a history view.
  • Used unquote method to convert quoted primary key back into its original form for history form view.

Description

This error occurs while rendering object URL with primary key in Change History view. This line causes the issue.

I was able to fix this issue using admin_urlquote filter on object.pk. However, it breaks history form view as it receives encoded value in object id and object does not exist with this value. To fix this, I used unquote method to to convert quoted primary key back into its original form for history form view.

I also used quote method in [revert_url method] (https://github.com/jazzband/django-simple-history/blob/master/simple_history/models.py#L481) to encode objects primary key for constructing URL for history form view.

Related Issue

#1295

Motivation and Context

History view of the object with "/" in primary key is broken in admin portal.

How Has This Been Tested?

  • I wrote unit tests that render a history view for an object with "/" in the primary key.
  • After making these changes some tests related to history form view were broken, because these tests was passing integer to history_form_view method and unquote method does not work with integers. I fixed those tests, by converting these ids to strings for assertion. In history_form_view method, I explicitly converted object id to string for unquote method.
  • I manually tested these changes via the admin portal after importing the django-simple-history package in a sample django application.
  • These changes affects areas of code that uses simple history urls in admin.

Screenshots (if appropriate):

Error Before this fix

Screenshot 2024-01-23 at 10 46 49 PM

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have run the pre-commit run command to format and lint.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have added my name and/or github handle to AUTHORS.rst
  • I have added my change to CHANGES.rst
  • All new and existing tests passed.

- Used quote method to convert a primary key value into a string that can be used in a URL for history view
- Used unquote method  to convert quoted primary key back into its original form for history form view
jazzband#1295
Copy link

codecov bot commented Jan 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f48b53d) 96.87% compared to head (e8b2887) 96.87%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1297   +/-   ##
=======================================
  Coverage   96.87%   96.87%           
=======================================
  Files          23       23           
  Lines        1278     1280    +2     
  Branches      211      211           
=======================================
+ Hits         1238     1240    +2     
  Misses         21       21           
  Partials       19       19           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@muneeb706 muneeb706 marked this pull request as ready for review January 24, 2024 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant