Bug 43395 - Traceback: univention.admin.defaults tries to modify default values
Traceback: univention.admin.defaults tries to modify default values
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UDM (Generic)
UCS 4.2
All Linux
: P5 normal (vote)
: UCS 4.2-1-errata
Assigned To: Johannes Keiser
Florian Best
:
Depends on:
Blocks: 41053
  Show dependency treegraph
 
Reported: 2017-01-23 10:20 CET by Philipp Hahn
Modified: 2017-08-04 16:05 CEST (History)
2 users (show)

See Also:
What kind of report is it?: Development Internal
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?: Yes
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number: 2017062221000458, 2017080221000161
Bug group (optional): External feedback
Max CVSS v3 score:
hahn: Patch_Available+


Attachments
unittest for univention.admin#property.default (2.87 KB, text/plain)
2017-01-23 10:20 CET, Philipp Hahn
Details
Fix udm property default handling (8.99 KB, patch)
2017-01-23 10:23 CET, Philipp Hahn
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp Hahn univentionstaff 2017-01-23 10:20:29 CET
Created attachment 8363 [details]
unittest for univention.admin#property.default

While doing QA for Bug #38110:
>>> o = univention.admin.handlers.container.dc.object(None, lo, po)
>>> o['name']='foo'
>>> o.create()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.7/univention/admin/handlers/__init__.py", line 306, in create
    return self._create()
  File "/usr/lib/pymodules/python2.7/univention/admin/handlers/__init__.py", line 712, in _create
    if self.has_key(name) and self.descriptions[name].default(self):
  File "/usr/lib/pymodules/python2.7/univention/admin/__init__.py", line 269, in default
    self.base_default[i] = self._replace(self.base_default[i], object)
TypeError: 'tuple' object does not support item assignment

Looks like dc is the only case where default is a tuple containing a template string:
$ grep -n default=\( management/univention-directory-manager-modules/modules/univention/admin/handlers/*/*.py
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/domaincontroller_backup.py:254:             default=('/dev/null', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/domaincontroller_backup.py:265:             default=('/bin/bash', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/domaincontroller_master.py:254:             default=('/dev/null', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/domaincontroller_master.py:265:             default=('/bin/bash', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/domaincontroller_slave.py:254:              default=('/dev/null', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/domaincontroller_slave.py:265:              default=('/bin/bash', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/linux.py:233:               default=('/dev/null', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/linux.py:244:               default=('/bin/bash', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/macos.py:233:               default=('/dev/null', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/macos.py:244:               default=('/bin/false', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/memberserver.py:254:                default=('/dev/null', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/memberserver.py:265:                default=('/bin/bash', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/ubuntu.py:233:              default=('/dev/null', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/ubuntu.py:244:              default=('/bin/bash', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/windows_domaincontroller.py:251:            default=('/dev/null', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/windows_domaincontroller.py:262:            default=('/bin/false', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/windows.py:246:             default=('/dev/null', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/computers/windows.py:257:             default=('/bin/false', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/container/dc.py:87:           default=('<name>.%s' % configRegistry.get('domainname', ''), []),
management/univention-directory-manager-modules/modules/univention/admin/handlers/container/dc.py:109:          default=(configRegistry.get('domainname', '').upper(), []),
management/univention-directory-manager-modules/modules/univention/admin/handlers/container/dc.py:130:          default=('1000', []),
management/univention-directory-manager-modules/modules/univention/admin/handlers/container/dc.py:141:          default=('1000', []),
management/univention-directory-manager-modules/modules/univention/admin/handlers/container/dc.py:152:          default=(configRegistry.get('domainname', '').upper(), []),
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/alias.py:77:              default=(('3', 'hours'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/forward_zone.py:76:               default=(('3', 'hours'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/forward_zone.py:87:               default=('root@%s' % configRegistry.get('domainname'), []),
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/forward_zone.py:98:               default=('1', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/forward_zone.py:109:              default=(('8', 'hours'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/forward_zone.py:120:              default=(('2', 'hours'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/forward_zone.py:131:              default=(('7', 'days'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/forward_zone.py:142:              default=(('3', 'hours'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/host_record.py:74:                default=(('3', 'hours'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/reverse_zone.py:74:               default=(('3', 'hours'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/reverse_zone.py:85:               default=('root@%s.' % configRegistry.get('domainname', ''), []),
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/reverse_zone.py:96:               default=('1', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/reverse_zone.py:107:              default=(('8', 'hours'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/reverse_zone.py:118:              default=(('2', 'hours'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/reverse_zone.py:129:              default=(('7', 'days'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/reverse_zone.py:140:              default=(('1', 'days'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/srv_record.py:83:         default=(('3', 'hours'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/txt_record.py:71:         default=(('22', 'hours'), [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/groups/group.py:115:          default=('2', []),
management/univention-directory-manager-modules/modules/univention/admin/handlers/groups/group.py:135:          default=('-2147483646', []),
management/univention-directory-manager-modules/modules/univention/admin/handlers/settings/default.py:65:               default=('univention', [])
management/univention-directory-manager-modules/modules/univention/admin/handlers/settings/directory.py:68:             default=('directory', [])

According to <https://billy.knut.univention.de/~fbest/coverage/2017-01-12/_usr_share_pyshared_univention_admin___init___py.html#n241> most of the code is not used and could be removed.
Comment 1 Philipp Hahn univentionstaff 2017-01-23 10:23:46 CET
Created attachment 8364 [details]
Fix udm property default handling

>>> issubclass(types.StringType, basestring)
True
>>> issubclass(types.UnicodeType, basestring)
True
Comment 2 Philipp Hahn univentionstaff 2017-01-23 10:48:32 CET
handlers/__init__.py@710
 »···»···for name, p in self.descriptions.items():
 »···»···»···# ... if property has no option or any required option is currently enabled
-»···»···»···if self.has_key(name) and self.descriptions[name].default(self):
-»···»···»···if self.has_key(name) and p.default(self):
Comment 3 Johannes Keiser univentionstaff 2017-06-22 12:00:14 CEST
Applied patch:
r 80406
univention-directory-manager-modules (12.0.17-16) 
* Bug #43395: Fix udm property default handling

-------
r 80408
univention-directory-manager-modules (12.0.17-17) 
* Bug #43395: Fix pyflakes warnings
Comment 4 Florian Best univentionstaff 2017-06-22 12:19:45 CEST
(In reply to Johannes Keiser from comment #3)
> r 80408
> univention-directory-manager-modules (12.0.17-17) 
> * Bug #43395: Fix pyflakes warnings

Please revert this as there is a lot of intentional behavior:
The imports are necessary.
object.has_key() is different to foo in object, see Bug #42787.
Comment 5 Florian Best univentionstaff 2017-06-22 12:25:51 CEST
This bug is now triggered in UMC when trying to modify the LDAP base.
It is now hit because of the changes in Bug #41053.

Execution of command 'udm/get navigation' has failed:

Traceback (most recent call last):
  File "%PY2.7%/notifier/threads.py", line 82, in _run
    tmp = self._function()
  File "%PY2.7%/notifier/__init__.py", line 104, in __call__
    return self._function( *tmp, **self._kwargs )
  File "%PY2.7%/univention/management/console/modules/udm/__init__.py", line 483, in _get
    if obj.has_key(name) and obj.descriptions[name].default(obj):  # noqa: W601
  File "%PY2.7%/univention/admin/__init__.py", line 283, in default
    self.base_default[i] = self._replace(self.base_default[i], object)
TypeError: 'tuple' object does not support item assignment
Comment 6 Florian Best univentionstaff 2017-06-22 12:41:29 CEST
We removed univention-directory-manager-modules/test/ during Bug #27286. Could you move the unit tests into an ucs-test case?
Comment 7 Johannes Keiser univentionstaff 2017-06-22 13:47:46 CEST
(In reply to Florian Best from comment #4)
> (In reply to Johannes Keiser from comment #3)
> > r 80408
> > univention-directory-manager-modules (12.0.17-17) 
> > * Bug #43395: Fix pyflakes warnings
> 
> Please revert this as there is a lot of intentional behavior:
> The imports are necessary.
> object.has_key() is different to foo in object, see Bug #42787.

r 80409
univention-directory-manager-modules (12.0.17-18) 
* Bug #43395: Revert commit r 80408

(In reply to Florian Best from comment #6)
> We removed univention-directory-manager-modules/test/ during Bug #27286.
> Could you move the unit tests into an ucs-test case?

r 80410
univention-directory-manager-modules (12.0.17-19) 
* Bug #43395: Move duplicated code into function and remove unittest

r 80411
Added test to ucs-test
Comment 8 Johannes Keiser univentionstaff 2017-06-22 14:42:28 CEST
YAML: r 80416
Comment 9 Florian Best univentionstaff 2017-06-22 16:32:14 CEST
OK: patch works nice
OK: ucs-test
OK: YAML
Comment 11 Florian Best univentionstaff 2017-08-04 16:05:21 CEST
Reported again, 4.2-0 errata85 (Lesum) - UCS@school 4.2 v1