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

Models do not override __hash__ making them unusable in hashed collections #38

Open
asqui opened this issue Jan 29, 2020 · 1 comment
Open

Comments

@asqui
Copy link

asqui commented Jan 29, 2020

Models such as Responders define the __eq__() and __ne__() methods appropriately, but not __hash__().

From the Python documentation:

If a class [...] defines __cmp__() or __eq__() but not __hash__(), its instances will not be usable in hashed collections.

The practical consequence of this is that set((Responders(type='team', name='foo'))) != set((Responders(type='team', name='foo'))) which is quite confusing!

I suspect that this may be a bug coming from the Open Api Generator, but I am not familiar with the generator implementation and its use so am raising this bug here in the first instance.

asqui added a commit to BATS/opsgenie-python-sdk that referenced this issue Feb 3, 2020
...so it can be used in hashable collection.

(This is a temporary patch to work around issue opsgenie#38)
asqui added a commit to BATS/opsgenie-python-sdk that referenced this issue Feb 3, 2020
* add-__hash__-to-models-opsgenie#38:
  Define __hash__ for Responders model
  ...so it can be used in hashable collection.
  (This is a temporary patch to work around issue opsgenie#38)
asqui added a commit to BATS/opsgenie-python-sdk that referenced this issue Feb 3, 2020
* add-__hash__-to-models-opsgenie#38:
  Define __hash__ for Responders model
asqui added a commit to BATS/opsgenie-python-sdk that referenced this issue Feb 3, 2020
...so it can be used in hashable collection.

(This is a temporary patch to work around issue opsgenie#38)
@asqui
Copy link
Author

asqui commented Feb 5, 2021

The fix for this is quite simple (see example here: BATS@5fceef1) and it would be good if this could be fixed here so that I don't need to maintain a separate fork with the workaround for this issue...

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

No branches or pull requests

1 participant