#33441: model Field.__hash__ should be immutable
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Adam
| Johnson
Type: Bug | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Adam Johnson):
> As far as I'm aware, fields are quite specific, in a real life they
don't live without models.
Yes the use case is contrived. But there are plenty of uses for fields in
ORM expressions that *might* lead one to create references to a field
before/after they are assigned to a model class.
> We shouldn't consider the same field instance assigned to a different
models as equal.
`__hash__` is never used for equality. The only requirement is that *IF*
two objects are equal, they have the same hash. There's no problem with
creating a `__hash__` that always does `return 1` - it will only make its
use in dictionaries slow.
Changing `__hash__` in the PR was unnecessary for the previous fix. I
believe it came from a misunderstanding around what `__hash__` means.
> IMO the current behavior is expected, we don't want to reintroduce an
issue fixed in 502e75f9ed5476ffe8229109acf0c23999d4b533.
I don't think there's any risk. The PR passes all tests, including the one
introduced, minus the unnecessary `hash()` assertions.
--
Ticket URL: <https://code.djangoproject.com/ticket/33441#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.74ad99f7342a0ed91e77d504d7122ddb%40djangoproject.com.