Shouldn't invalid hashid throw a DoesNotExist instead of a TypeError
See original GitHub issueI am using a hash-id field for one of my models in a small private project. The Hash-ID is used in URLs to access the model instance. I recently had to change the HASHID_FIELD_SALT
essentially invalidating all existing links, but as it is only a small project, I didn’t worry about it too much.
Now some of my users still had old links but as I use get_object_or_404
to retrieve the model from the database, I thought I’d be save, as I thought the users with the old links would simply get a 404 error. This is, however, not the case. The Hash-ID Field throws a TypeError: value must be a positive integer or a valid Hashids string
on a old Hash-ID. As the Hash-ID has the same length as the expected Hash-ID, I would expect the Model to throw a DoesNotExist
Exception that would be caught by get_object_or_404
.
Is this behavior desired? Otherwise I would propose to change the behavior to throw a DoesNotExist
if the hash-id is of the expected length but not valid.
I can also provide a pull-request for this issue if you’d consent to my proposal.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
OK, I went with option 3, plus a couple other small changes, and I’m going to call it version 2.0.0 since it has the potential to break existing behavior. Check it out with
I’ll take another look at the changes tomorrow, and if nothing else comes to mind, publish it.
This is fixed in 2.0.1. Please read the CHANGELOG for upgrading instructions.