question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shouldn't invalid hashid throw a DoesNotExist instead of a TypeError

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nshafercommented, Oct 3, 2017

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

pip install --upgrade git+https://github.com/nshafer/django-hashid-field.git@empty_lookups

I’ll take another look at the changes tomorrow, and if nothing else comes to mind, publish it.

0reactions
nshafercommented, Oct 4, 2017

This is fixed in 2.0.1. Please read the CHANGELOG for upgrading instructions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python poetry install failure - invalid hashes - Stack Overflow
There are several issue reports about invalid hashes. One common cause is running multiple Poetry instances simultaneously; another is ...
Read more >
Property does not exist on type String in TypeScript | bobbyhadz
The "Property does not exist on type String" error occurs when we try to access a property that does not exist on the...
Read more >
Errors | Node.js v18 API
Throws with a ReferenceError because z is not defined. try { const m = 1; ... If present, error.path is a string containing...
Read more >
12587 (simplicial complexes lack hash function) - Sage Trac
Because of this, I would like for it to be handled like Graph and throw a TypeError?. However there are many dependencies on...
Read more >
CoffeeScript
The command-line version of coffee is available as a Node.js utility, requiring Node 6 or later. The core compiler however, does not depend...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found