#6502 SchemaPlugin does not implement __eq__ and __hash__
Opened 3 years ago by cheimes. Modified 3 years ago

{{{ipaclient.remote_plugins.schema._SchemaPlugin}}} instances are registered as plugins and added to the set of plugins ipalib.api._plugins. The base class does not provide hash and thus uses the default implementation of hash which uses id(self).

The default implementation of __eq__ and __hash__ is not well-suited for user defined classes. It assumes that all instances of a class are singletons. In case some code adds a second schema object with the same name and version, we end up with duplicated entries in a set or dict. We are just lucky that we don't have conflicts at the moment. Distinct names are not guaranteed by the design of the schema cache, though.

Therefore SchemaPlugin should implement __eq__ to only compare equally to other SchemaPlugin instances with same name and version. The hash of SchemaPlugin instances should depend on name and version, too.


User-defined classes have __eq__() and __hash__() methods by default; with them, all objects compare unequal (except with themselves) and x.__hash__() returns an appropriate value such that x == y implies both that x is y and hash(x) == hash(y).

Metadata Update from @cheimes:
- Issue assigned to someone
- Issue set to the milestone: Future Releases

3 years ago

Login to comment on this ticket.