Univention Bugzilla – Bug 33101
UCR does not fullfill Python dict contract
Last modified: 2017-04-04 18:29:26 CEST
univention.config_registry.ConfigRegistry inherits from dict() and overwrites several methods, which breaks the Python contract for dictionaries <http://docs.python.org/2.6/library/stdtypes.html#mapping-types-dict>: from univention.config_registry import ConfigRegistry ucr = ConfigRegistry() ucr.load() dict(ucr) # → {} list(ucr.itervalues()) # → [] list(ucr.iteritems()) # → [] <http://docs.python.org/2.6/library/userdict.html#UserDict.DictMixin> or <http://docs.python.org/2.6/library/collections.html#MutableMapping> should be considered
To get an idea about the priority. For what do we need it?
(In reply to Stefan Gohmann from comment #1) > To get an idea about the priority. For what do we need it? Additional time to debug unexpected behavior and find a work-around. I know of at least two occurrences where people used ucr.iteritems() first and later on had to change the code to use ucr.items() adding a comment warning about ucr not following the dict contract. This is no serious bug, but still costs time to debug and you have to know, that ucr is special ...
(In reply to Philipp Hahn from comment #2) > (In reply to Stefan Gohmann from comment #1) > > To get an idea about the priority. For what do we need it? > > Additional time to debug unexpected behavior and find a work-around. > > I know of at least two occurrences where people used ucr.iteritems() first > and later on had to change the code to use ucr.items() adding a comment > warning about ucr not following the dict contract. This is no serious bug, > but still costs time to debug and you have to know, that ucr is special ... OK, as long as we did not change it we could add a short hint at the dev guide: http://docs.univention.de/developer-reference-3.2.html#ucr:usage:python Everybody who starts with the UCR programming can read it.
Re-check for UCS 4.
Still miserable in UCS 4.2.
Again: r73453 (In reply to Stefan Gohmann from comment #3) > OK, as long as we did not change it we could add a short hint at the dev > guide: > http://docs.univention.de/developer-reference-3.2.html#ucr:usage:python > > Everybody who starts with the UCR programming can read it. and will forget it after 1 week of doing other things.
Occurred again in svn r74123.
Use <https://docs.python.org/2.7/library/collections.html#collections.MutableMapping>?
Created attachment 8266 [details] Use collection.MutableMapping instead of dict as base class
Debugged again while trying to use it with str.format() and key based formatting. Statements like the following also access the (unused) dict structure created by inheriting from dict instead of the ones in ConfigRegistry._registry: '{version/version}'.format(ucr) This results in KeyError.
r76603 | Bug #33101 ucr: Fix UCR dict contract Package: univention-config-registry Version: 12.0.1-3A~4.2.0.201702101358 Branch: ucs_4.2-0 (In reply to Eduard Mai from comment #10) > Debugged again while trying to use it with str.format() and key based > formatting. Statements like the following also access the (unused) dict > structure created by inheriting from dict instead of the ones in > ConfigRegistry._registry: > > '{version/version}'.format(ucr) > > This results in KeyError. Your "syntax" is wrong here, see last two lines: print '{version/version}'.format({'version/version':42}) # Traceback (most recent call last): # File "<stdin>", line 1, in <module> # KeyError: 'version/version' from univention.config_registry import ConfigRegistry ucr = ConfigRegisry() ucr.load() print ucr['version/version'] print ucr.get('version/version') print '%(version/version)s' % ucr print '{version/version}'.format(**ucr) print '{0[version/version]}'.format(ucr)
1. Please comment something about this API change: Prior: >>> ucr['foo'] '' >>> ucr.get('foo') '' >>> ucr.items(getscope=ConfigRegistry.SCHEDULE) … Afterwards: >>> ucr['foo'] >>> ucr.get('foo') 2. $ ucr search foo E: your request could not be fulfilled try `univention-config-registry --help` for more information >>> from univention.config_registry.frontend import handler_search >>> handler_search([]) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/pymodules/python2.7/univention/config_registry/frontend.py", line 329, in handler_search for key, (scope, value) in ucr.items(getscope=True): TypeError: items() got an unexpected keyword argument 'getscope' >>> ucr.items(getscope=ConfigRegistry.SCHEDULE) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: items() got an unexpected keyword argument 'getscope'
(In reply to Florian Best from comment #12) > 1. Please comment something about this API change: > Prior: > >>> ucr['foo'] is '' ... > Afterwards: > >>> ucr['foo'] is None This was caused by "foo" being set to '' in your test: > # grep ^foo: /etc/univention/base*.conf > /etc/univention/base.conf:foo: > 2. > >>> from univention.config_registry.frontend import handler_search;handler_search([]) ... > TypeError: items() got an unexpected keyword argument 'getscope' r76606 | Bug #33101 ucr: Re-add item(getscope=True) custom implementation Fixed Package: univention-config-registry Version: 12.0.1-4A~4.2.0.201702101623 Branch: ucs_4.2-0
OK Changelog: OK
UCS 4.2 has been released: https://docs.software-univention.de/release-notes-4.2-0-en.html https://docs.software-univention.de/release-notes-4.2-0-de.html If this error occurs again, please use "Clone This Bug".