Univention Bugzilla – Bug 48045
Classes are not removed if none are set in the infile
Last modified: 2019-03-30 08:41:41 CET
Classes are not removed if none are set in the infile If a teacher is imported without classes (empty string) any previously set classes are not removed by the importer. Changing classes removes the old class. See bug 48028 for more information. I think we should make the behavior consistent with other imported fields. UCS 4.4 might be a good time to change this. Maybe a ucr variable should be set for old installation to not change that behavior?
Change docu (see https://forge.univention.org/bugzilla/show_bug.cgi?id=48028)
The ucsschool import and the underlying ucsschool.lib now remove a user from its school classes, if the school_classes attribute is empty. This is an API breaking change! The ucsschool import (not the lib!) supports a backwards compatibility switch in the JSON configuration: --------------------------- { "school_classes_keep_if_empty": true } --------------------------- The legacy import that is based upon the import framework has this variable set to true. The ucs-test 214_import-users_empty_class_column was extended to test both settings (school_classes_keep_if_empty=False is the default). [4.4] 944030e75 Bug #48045: Bug #48045: remove classes if none are set in the infile / school_classes attribute [4.4] da3ad2464 Bug #48045: Bug #48045: remove classes if none are set in the school_classes attribute [4.4] 32df3c257 Bug #48045: Bug #48045: make ucslint happy [4.4] 0057ca5ea Bug #48045: test new behavior of classes removal [4.4] 967035985 Bug #48045: advisories Documentation commit with change was labeled with wrong bug number: [4.4] 44c53983a Bug #48045: document changed behavior ucs-school-lib (12.1.0-1) ucs-school-import (17.2.0-1) (Minor versions raised because of API change.)
Test 34_import-users_via_cli fails: [2019-02-11 14:37:52.129193] Traceback (most recent call last): [2019-02-11 14:37:52.129222] File "/usr/lib/pymodules/python2.7/ucsschool/importer/mass_import/mass_import.py", line 110, in import_users [2019-02-11 14:37:52.129250] user_import.create_and_modify_users(imported_users) # 90% - 100% [2019-02-11 14:37:52.129277] File "/usr/lib/pymodules/python2.7/ucsschool/importer/mass_import/user_import.py", line 203, in create_and_modify_users [2019-02-11 14:37:52.129303] success = user.create(lo=self.connection) [2019-02-11 14:37:52.129331] File "/usr/lib/pymodules/python2.7/ucsschool/importer/models/import_user.py", line 332, in create [2019-02-11 14:37:52.129357] res = super(ImportUser, self).create(lo, validate) [2019-02-11 14:37:52.129384] File "/usr/lib/pymodules/python2.7/ucsschool/lib/models/base.py", line 459, in create [2019-02-11 14:37:52.129408] success = self.create_without_hooks(lo, validate) [2019-02-11 14:37:52.129440] File "/usr/lib/pymodules/python2.7/ucsschool/lib/models/base.py", line 472, in create_without_hooks [2019-02-11 14:37:52.129466] self.validate(lo) [2019-02-11 14:37:52.129550] File "/usr/lib/pymodules/python2.7/ucsschool/importer/legacy/legacy_import_user.py", line 85, in validate [2019-02-11 14:37:52.129581] super(LegacyImportUser, self).validate(lo, validate_unlikely_changes, check_username) [2019-02-11 14:37:52.129606] File "/usr/lib/pymodules/python2.7/ucsschool/importer/models/import_user.py", line 997, in validate [2019-02-11 14:37:52.129629] super(ImportUser, self).validate(lo, validate_unlikely_changes) [2019-02-11 14:37:52.129654] File "/usr/lib/pymodules/python2.7/ucsschool/lib/models/user.py", line 413, in validate [2019-02-11 14:37:52.129679] if school.lower() not in map(str.lower, self.schools): [2019-02-11 14:37:52.129704] TypeError: descriptor 'lower' requires a 'str' object but received a 'unicode'
[4.4] cfb56800d Bug #48045: use lower() of both str and unicode ucs-school-lib (12.1.0-3)
Changelog & Advisory: OK Packages install: OK Tests pass on Jenkins: OK Classes are removed if import field is empty (empty string, empty, etc): OK keep classes flag works: OK Classes are removed if field is cleared in lib: OK Seems all as intended. Remark: The package versions stated in this ticket are not valid anymore, since they were changed afterwards
Addition: Doc: OK
If no mapping for classes is set, all class information will be removed upon a new import. This has to be avoided.
Please read comment #2.
Now it isn't consistent again. Classes seem to be the only attribute that get removed if not mapped.
The problem with the school_classes property is, that the ucsschool.lib sets its initial value to {} if empty. So we cannot easily distinguish from its current value if the input was empty or there was no input (no mapping). But luckily we can access the original input data. The behavior is now: * if there is a mapping for school_classes - if the CSV-data is non-empty → set new school_classes - if the CSV-data is empty - if config[school_classes_keep_if_empty] is True → keep previous school_classes - else → empty school_classes * if there is no mapping for school_classes → keep previous school_classes [4.4 9537b9d7a] Bug #48045: figure out why the school_class property is empty and handle accordingly ucs-school-import 17.0.4-7A~4.4.0.201902221250
(In reply to Daniel Tröder from comment #10) > The behavior is now: > > * if there is a mapping for school_classes > - if the CSV-data is non-empty → set new school_classes > - if the CSV-data is empty > - if config[school_classes_keep_if_empty] is True → keep previous > school_classes > - else → empty school_classes > * if there is no mapping for school_classes → keep previous school_classes Great!
Changelog & Advisory: OK Package installs: OK Behaves as defined in Comment #10: OK Everything works now according to the defined behavior.
UCS@school 4.4 v1 has been released. https://docs.software-univention.de/release-notes-ucsschool-4.4v1-de.html If this error occurs again, please clone this bug.