Bug 41642 - Validation failure for birthday attribute
Validation failure for birthday attribute
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: Import scripts
UCS@school 4.1 R2
Other Linux
: P5 normal (vote)
: UCS@school 4.1 R2 vXXX
Assigned To: Daniel Tröder
Sönke Schwardt-Krummrich
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2016-06-22 20:00 CEST by Jan Christoph Ebersbach
Modified: 2016-10-06 21:12 CEST (History)
3 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 3: Simply Wrong: The implementation doesn't match the docu
Who will be affected by this bug?: 2: Will only affect a few installed domains
How will those affected feel about the bug?: 2: A Pain – users won’t like this once they notice it
User Pain: 0.069
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments
schueler.csv (150 bytes, text/csv)
2016-06-22 20:01 CEST, Jan Christoph Ebersbach
Details
myformat.json (652 bytes, application/json)
2016-06-22 20:02 CEST, Jan Christoph Ebersbach
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Christoph Ebersbach univentionstaff 2016-06-22 20:00:25 CEST
I created my own import configuration for a new file format.  When I tried to import a user I got the following error message.  It looks like birthday has already been converted into a date object and back into a string including "time".  This string is then validated against iso8601 which inevitably fails:


2016-06-15 12:04:07 DEBUG base.cache:209  Initializing ('School', ('name', 'schule1'))
2016-06-15 12:04:07 DEBUG base.get_udm_object:650  Getting School UDM object by dn: ou=schule1,dc=univention,dc=schule,dc=intranet
2016-06-15 12:04:07 DEBUG base.get_only_udm_obj:853  Getting ImportStudent UDM object by filter: &(!(uid=Elena.Sc5))(mailPrimaryAddress=elena.schrage[counter2]@schule.intranet)
2016-06-15 12:04:08 ERROR user_import.create_and_modify_users:190  Entry #0: ValidationError when adding ImportStudent(name='Elena.Sc5', school='schule1', dn='uid=Elena.Sc5,cn=schueler,cn=users,ou=schule1,dc=univention,dc=schule,dc=intranet', old_dn=None) (source_uid:mydb record_uid:  2001-11-03): {'birthday': ['The given date does not conform to iso8601, example: "2009-01-01".']}
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/ucsschool/importer/mass_import/user_import.py", line 140, in create_and_modify_users
    success = user.create(lo=self.connection)
  File "/usr/lib/pymodules/python2.7/ucsschool/importer/models/import_user.py", line 631, in create
    return super(ImportUser, self).create(lo, validate)
  File "/usr/lib/pymodules/python2.7/ucsschool/lib/models/base.py", line 417, in create
    success = self.create_without_hooks(lo, validate)
  File "/usr/lib/pymodules/python2.7/ucsschool/importer/models/import_user.py", line 634, in create_without_hooks
    success = super(ImportUser, self).create_without_hooks(lo, validate)
  File "/usr/lib/pymodules/python2.7/ucsschool/lib/models/base.py", line 430, in create_without_hooks
    raise ValidationError(self.errors.copy())
UserValidationError: ValidationError when adding ImportStudent(name='Elena.Sc5', school='schule1', dn='uid=Elena.Sc5,cn=schueler,cn=users,ou=schule1,dc=univention,dc=schule,dc=intranet', old_dn=None) (source_uid:mydb record_uid:  2001-11-03): {'birthday': ['The given date does not conform to iso8601, example: "2009-01-01".']}
Comment 1 Jan Christoph Ebersbach univentionstaff 2016-06-22 20:01:17 CEST
Created attachment 7764 [details]
schueler.csv

Import data
Comment 2 Jan Christoph Ebersbach univentionstaff 2016-06-22 20:02:48 CEST
Created attachment 7765 [details]
myformat.json

Import is run with the following command
/usr/share/ucs-school-import/scripts/ucs-school-user-import -c myformat.json -i schueler.csv -u student
Comment 3 Jan Christoph Ebersbach univentionstaff 2016-06-22 20:16:08 CEST
In /usr/lib/pymodules/python2.7/ucsschool/importer/models/import_user.py:531 the following command is executed:

    self.birthday = datetime.datetime.strptime(self.birthday, "%Y-%m-%d").isoformat()

However, this produces the wrong output:

(Pdb) datetime.datetime.strptime(self.birthday, "%Y-%m-%d").isoformat()
'2001-11-03T00:00:00'

The following call would fix the issue.  However, I'm not sure if it's at all necessary since the actual validation comes later anyway:

     datetime.datetime.strptime(self.birthday, "%Y-%m-%d").strftime('%Y-%m-%d')
Comment 4 Daniel Tröder univentionstaff 2016-06-23 08:37:22 CEST
(In reply to Jan Christoph Ebersbach from comment #3)
> In /usr/lib/pymodules/python2.7/ucsschool/importer/models/import_user.py:531
> the following command is executed:
> 
>     self.birthday = datetime.datetime.strptime(self.birthday,
> "%Y-%m-%d").isoformat()
> 
> However, this produces the wrong output:
> 
> (Pdb) datetime.datetime.strptime(self.birthday, "%Y-%m-%d").isoformat()
> '2001-11-03T00:00:00'
> 
> The following call would fix the issue.  However, I'm not sure if it's at
> all necessary since the actual validation comes later anyway:
> 
>      datetime.datetime.strptime(self.birthday,
> "%Y-%m-%d").strftime('%Y-%m-%d')
Confirmed.
Actually no assignment to self.birthday should be done - just the parsing of the string to validate it.

The reason to check this here is to give the user a good explanation of what's wrong, instead of waiting for UDM to fail, but User.create() only returning "False".


Fixed in r70551.
Advisory in r70552.
Comment 5 Sönke Schwardt-Krummrich univentionstaff 2016-07-03 23:33:15 CEST
ucs-test-ucsschool (3.0.13-2):
r70723 | Bug #41642: add test for ISO birthday values

OK: functional test
OK: YAML
OK: code change
Comment 6 Sönke Schwardt-Krummrich univentionstaff 2016-07-04 12:06:32 CEST
UCS@school 4.1 R2 v2 has been released.

If this error occurs again, please clone this bug.