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

Remove comment and set up explicit __hash__ function #3979

Merged
merged 2 commits into from Apr 26, 2019

Conversation

akjanik
Copy link
Contributor

@akjanik akjanik commented Apr 17, 2019

It turns out that in Django 2.2 bug we were unknowingly relying on was fixed. Indeed, from https://docs.python.org/3/reference/datamodel.html#object.__hash__

A class that overrides eq() and does not define hash() will have its hash() implicitly set to None.

If a class that overrides eq() needs to retain the implementation of hash() from a parent class, the interpreter must be told this explicitly by setting hash = .hash.

Additional explanation of the issue:
https://code.djangoproject.com/ticket/30333

Pull Request Checklist

  1. Privileged views and APIs are guarded by proper permission checks.
  2. All visible strings are translated with proper context.
  3. All data-formatting is locale-aware (dates, numbers, and so on).
  4. Database queries are optimized and the number of queries is constant.
  5. Database migration files are up to date.
  6. The changes are tested.
  7. The code is documented (docstrings, project documentation).
  8. GraphQL schema and type definitions are up to date.
  9. Changes are mentioned in the changelog.

@codecov
Copy link

codecov bot commented Apr 17, 2019

Codecov Report

Merging #3979 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3979      +/-   ##
==========================================
- Coverage   91.28%   91.27%   -0.01%     
==========================================
  Files         275      267       -8     
  Lines       14957    14514     -443     
  Branches     1450     1385      -65     
==========================================
- Hits        13653    13248     -405     
+ Misses        913      897      -16     
+ Partials      391      369      -22
Impacted Files Coverage Δ
saleor/checkout/models.py 98.85% <100%> (-0.02%) ⬇️
saleor/account/models.py 92.03% <100%> (-0.07%) ⬇️
saleor/graphql/product/filters.py 82.85% <0%> (-7.55%) ⬇️
saleor/graphql/product/enums.py 87.87% <0%> (-2.6%) ⬇️
saleor/graphql/core/mutations.py 93.72% <0%> (-1.67%) ⬇️
saleor/product/utils/availability.py 95.45% <0%> (-1.57%) ⬇️
saleor/checkout/views/__init__.py 83.45% <0%> (-0.92%) ⬇️
saleor/graphql/product/resolvers.py 93.81% <0%> (-0.76%) ⬇️
saleor/account/forms.py 84.61% <0%> (-0.76%) ⬇️
saleor/discount/models.py 83.05% <0%> (-0.56%) ⬇️
... and 51 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d3cabd2...b710f0c. Read the comment docs.

def __hash__(self):
# FIXME: in Django 2.2 this is not present if __eq__ is defined
return super().__hash__()
__hash__ = models.Model.__hash__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there cases where __eq__ would return False while __hash__ remains True? Because this will break Python.

@maarcingebala maarcingebala merged commit c916cb2 into master Apr 26, 2019
@maarcingebala maarcingebala deleted the remove_wrong_fixme_hash branch April 26, 2019 12:26
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.

None yet

4 participants