Univention Bugzilla – Bug 41642
Validation failure for birthday attribute
Last modified: 2016-10-06 21:12:24 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".']}
Created attachment 7764 [details] schueler.csv Import data
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
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')
(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.
ucs-test-ucsschool (3.0.13-2): r70723 | Bug #41642: add test for ISO birthday values OK: functional test OK: YAML OK: code change
UCS@school 4.1 R2 v2 has been released. If this error occurs again, please clone this bug.