Bug 53816 - Traceback during import, when deactivating a user instead of deleting and mandatory attributes are involved
Traceback during import, when deactivating a user instead of deleting and man...
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 5.0
Other Linux
: P5 normal (vote)
: UCS@school 5.0 v1
Assigned To: Jürn Brodersen
Ole Schwiegert
:
Depends on: 53649
Blocks:
  Show dependency treegraph
 
Reported: 2021-09-21 12:42 CEST by Jürn Brodersen
Modified: 2021-11-29 17:19 CET (History)
4 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 4: Minor Usability: Impairs usability in secondary scenarios
Who will be affected by this bug?: 2: Will only affect a few installed domains
How will those affected feel about the bug?: 5: Blocking further progress on the daily work
User Pain: 0.229
Enterprise Customer affected?:
School Customer affected?: Yes
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number: 2021081121000396
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jürn Brodersen univentionstaff 2021-09-21 12:42:16 CEST
+++ This bug was initially created as a clone of Bug #53649 +++

The following traceback occurs, if an imported user should be deleted after a specified amount of time. 'deletion_grace_period' is set to e.g. 90 in the json file.

Short extract from the json:

-----------------------------------------------------------------

                "mapping": {
                        "vorname": "firstname",
                        "familienname": "lastname",
                        "klasse": "school_classes",
                        "geburtsdatum": "birthday",
                        "schueler_stamm_id": "employeeNumber"
                }
        },
        "maildomain": "edukl.xyz",
        "scheme": {
                "record_uid": "<school>-<employeeNumber>",
                "username": {
                        "default": "<firstname>[0:3]<lastname>[0:5]<:lower>[COUNTER2]"
                },
                "email": "<username>@<school>.<maildomain>"
        },
        "activate_new_users": {
                "default": true
        },
        "deletion_grace_period": {
                "deactivation": 0,
                "deletion": 90
        },
        "mandatory_attributes": ["firstname", "lastname", "name", "record_uid", "school", "source_uid", "birthday", "employeeNumber"],
        "no_delete": false,
------------------------------------------

It seems the mandatory attribute employeeNumber is the problem, but the filter could not match at all?
Getting ImportStudent UDM object by filter: &(!(uid=flodietr))(mailPrimaryAddress=flodietr@one.schein.qa)
The user should be deactivated, and is not deleted, and should not at this moment.



------ Read 12 users from input data. ------  
------ Detecting which users to delete... ------
Searching with filter='(&(&(objectClass=ucsschoolStudent)(!(objectClass=ucsschoolExam)))(ucsschoolSourceUID=edoosys-one-student)(ucsschoolRecordUID=*))'
users_to_delete=[(u'edoosys-one-student', u'one-40282097/3333/0174/0bb96e62/7bde', [])]
------ Deleting 1 users... ------
Getting ImportUser UDM object by filter: (&(&(objectClass=ucsschoolStudent)(!(objectClass=ucsschoolExam)))(ucsschoolSourceUID=edoosys-one-student)(ucsschoolRecordUID=one-
40282097/3333/0174/0bb96e62/7bde))
UDM object uid=flodietr,cn=schueler,cn=users,ou=one,dc=schein,dc=qa is not ImportUser, but actually ImportStudent
Deactivating user ImportStudent(name='flodietr', school='one', dn='uid=flodietr,cn=schueler,cn=users,ou=one,dc=schein,dc=qa')...
Setting deletion grace date of ImportStudent(name='flodietr', school='one', dn='uid=flodietr,cn=schueler,cn=users,ou=one,dc=schein,dc=qa') to '2021-11-09'...
Searching for hooks of type 'UserPyHook' in: /usr/share/ucs-school-import/pyhooks...
Found hook classes:
Loaded hooks: {}.
Starting ImportStudent.call_hooks('pre', 'modify', lo('cn=admin,dc=schein,dc=qa')) for ImportStudent(name='flodietr', school='one', dn='uid=flodietr,cn=schueler,cn=users,
ou=one,dc=schein,dc=qa').
Hook directory /usr/share/ucs-school-import/hooks/user_modify_pre.d not found or empty.
Searching for hooks of type 'Hook' in: /var/lib/ucs-school-lib/hooks...
Found hook classes:
Loaded hooks: {}.
Modifying ImportStudent(name='flodietr', school='one', dn='uid=flodietr,cn=schueler,cn=users,ou=one,dc=schein,dc=qa')
Getting School UDM object by dn: ou=one,dc=schein,dc=qa
Getting ImportStudent UDM object by filter: &(!(uid=flodietr))(mailPrimaryAddress=flodietr@one.schein.qa)

Error in entry #0: Mandatory attribute u'employeeNumber' does not exist.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/mass_import/user_import.py", line 480, in delete_users
    success = self.do_delete(user)
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/mass_import/user_import.py", line 614, in do_delete
    success = user.modify(lo=self.connection)
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/models/import_user.py", line 1056, in modify
    res = super(ImportUser, self).modify(lo, validate, move_if_necessary)
  File "/usr/lib/python2.7/dist-packages/ucsschool/lib/models/base.py", line 674, in modify
    success = self.modify_without_hooks(lo, validate, move_if_necessary)
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/models/import_user.py", line 1092, in modify_without_hooks
    return super(ImportUser, self).modify_without_hooks(lo, validate, move_if_necessary)
  File "/usr/lib/python2.7/dist-packages/ucsschool/lib/models/base.py", line 689, in modify_without_hooks
    self.validate(lo, validate_unlikely_changes=True)
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/models/import_user.py", line 1238, in validate
    import_user=self,
MissingMandatoryAttribute: Mandatory attribute u'employeeNumber' does not exist.
More than 0 errors.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/mass_import/mass_import.py", line 124, in import_users
    user_import.delete_users(users_to_delete)  # 0% - 10%
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/mass_import/user_import.py", line 500, in delete_users
    self._add_error(exc)
  File "/usr/lib/python2.7/dist-packages/ucsschool/importer/mass_import/user_import.py", line 781, in _add_error
    "More than {} errors.".format(self.config["tolerate_errors"]), self.errors
TooManyErrors: More than 0 errors.
------ User import statistics ------
Read users from input data: 0
Errors: 2
Entry |   User    | Error description
-------------------------------------
    0 |  flodietr | Mandatory attribute u'employeeNumber' does not exist.
    0 | <No name> | More than 0 errors.
------ End of user import statistics ------   
------ Writing new users passwords to /data/01/tmp/import/hbg/output/2021/08/user/edoosys/student/11_141429_passwd.csv... ------
Searching for hooks of type 'ResultPyHook' in: /usr/share/ucs-school-import/pyhooks...
Found hook classes:
Loaded hooks: {}.
------ Importing users done. ------


The user has its employeeNumber:

univention-ldapsearch -LLL uid=flodietr dn employeeNumber
dn: uid=flodietr,cn=schueler,cn=users,ou=one,dc=schein,dc=qa
employeeNumber: 40282097/3333/0174/0bb96e62/7bde

I could reproduce it in my testenvironment, if you need the files, they are in the ticket or in my environment.
Comment 1 Jürn Brodersen univentionstaff 2021-09-23 09:59:46 CEST
For a discussion about this see bug 53649 comment 5

This bug differs from bug 53649 in the way that "get_imported_udm_property_names" is now mandatory for reader classes. The BaseReader class supplies a basic implementation, returning an empty list.

[5.0 b9d0acc6b] Bug #53816: fix traceback deactivating an importuser
[5.0 682c6d246] Bug #53816: Load udm_properties for users to be deleted
[5.0 afb2162b5] Bug #53816: Clear description to test disabled validation
[5.0 fa1cf2707] Bug #53816: test that udm_properties are loaded in remove hooks
[5.0 8de9875f4] Bug #53816: get_imported_udm_property_names is now mandatory
[5.0 71662ca32] Bug #53816: 5.0 changelog
[5.0 da7e0c2c5] Bug #53816: changelog
[5.0 aecc3e6bf] Bug #53816: changelog
Comment 2 Jürn Brodersen univentionstaff 2021-09-23 10:01:46 CEST
I reverted the wait time for the s4 connector back to 60s seconds. The test "253_import-users_deactivate.py" was flaky and updated the ucs-test runner to python3.

[5.0 e07491b9a] Bug #53816: update ucs-test runner to python3
[5.0 4687686b2] Bug #53816: revert s4 sleep to 60s
Comment 3 Ole Schwiegert univentionstaff 2021-09-27 10:46:57 CEST
OK: Tests fail before update
OK: Tests pass after update
OK: Reproduce problem
OK: Manual import tests work with delete hook
OK: Advisory&Changelog
Comment 4 Jürn Brodersen univentionstaff 2021-11-29 17:19:56 CET
UCS@school 5.0 v1 has been released.

https://docs.software-univention.de/release-notes-ucsschool-5.0v1-de.html

If this error occurs again, please clone this bug.