TypeError at deserializing malformed Date and DateTime #111

Closed
leplatrem opened this Issue May 30, 2013 · 14 comments

Projects

None yet

6 participants

Version 1.0a2 is ok, it raises Invalid.

>>>colander.SchemaNode(colander.DateTime()).deserialize('2013/05/31')
Traceback (most recent call last):
 ...
 ...
colander.Invalid: {'': u'Invalid date'}

Version 1.0a3 crashes, and raises TypeError:

>>> colander.SchemaNode(colander.DateTime()).deserialize('2013/05/31')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/__init__.py", line 1864, in deserialize
    appstruct = self.typ.deserialize(self, cstruct)
  File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/__init__.py", line 1492, in deserialize
    cstruct, default_timezone=self.default_tzinfo)
  File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/iso8601.py", line 137, in parse_date
    return datetime(int(groups["year"]), int(groups["month"]), int(groups["day"]),
TypeError: int() argument must be a string or a number, not 'NoneType'

Try replacing the forward slashes with dashes: colander.SchemaNode(
colander.DateTime()).deserialize('2013/05/31') works for me. Although, I
find it quite strange that slashes don't work.

On Thu, May 30, 2013 at 4:14 PM, Mathieu Leplatre
notifications@github.comwrote:

Version 1.0a2 is ok:

colander.SchemaNode(colander.DateTime()).deserialize('2013/05/31')
Traceback (most recent call last):
...
...
colander.Invalid: {'': u'Invalid date'}

Version 1.0a3:

colander.SchemaNode(colander.DateTime()).deserialize('2013/05/31')
Traceback (most recent call last):
File "", line 1, in
File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/init.py", line 1864, in deserialize
appstruct = self.typ.deserialize(self, cstruct)
File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/init.py", line 1492, in deserialize
cstruct, default_timezone=self.default_tzinfo)
File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/iso8601.py", line 137, in parse_date
return datetime(int(groups["year"]), int(groups["month"]), int(groups["day"]),
TypeError: int() argument must be a string or a number, not 'NoneType'


Reply to this email directly or view it on GitHubhttps://github.com/Pylons/colander/issues/111
.

Vincent Catalano
Software Engineer and Web Ninja,
(520).603.8944

Oops. I meant to say:

colander.SchemaNode(colander.DateTime()).deserialize('2013-05-31')

works for me instead.

On Thu, May 30, 2013 at 4:35 PM, Vincent Catalano <
vincent@vincentcatalano.com> wrote:

Try replacing the forward slashes with dashes: colander.SchemaNode(
colander.DateTime()).deserialize('2013/05/31') works for me. Although, I
find it quite strange that slashes don't work.

On Thu, May 30, 2013 at 4:14 PM, Mathieu Leplatre <
notifications@github.com> wrote:

Version 1.0a2 is ok:

colander.SchemaNode(colander.DateTime()).deserialize('2013/05/31')
Traceback (most recent call last):
...
...
colander.Invalid: {'': u'Invalid date'}

Version 1.0a3:

colander.SchemaNode(colander.DateTime()).deserialize('2013/05/31')
Traceback (most recent call last):
File "", line 1, in
File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/init.py", line 1864, in deserialize
appstruct = self.typ.deserialize(self, cstruct)
File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/init.py", line 1492, in deserialize
cstruct, default_timezone=self.default_tzinfo)
File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/iso8601.py", line 137, in parse_date
return datetime(int(groups["year"]), int(groups["month"]), int(groups["day"]),
TypeError: int() argument must be a string or a number, not 'NoneType'


Reply to this email directly or view it on GitHubhttps://github.com/Pylons/colander/issues/111
.

Vincent Catalano
Software Engineer and Web Ninja,
(520).603.8944

Vincent Catalano
Software Engineer and Web Ninja,
(520).603.8944

Colander is supposed to raise Invalid with malformed dates, as in previous versions, and not to crash with TypeError. I updated the description for less confusion :)

@mcdonc mcdonc added a commit that referenced this issue May 31, 2013
@mcdonc mcdonc - Fix bug introduced by supporting spec-mandated truncations of ISO-8601
  timezones.  A TypeError would be raised instead of Invalid.  See
  #111.

Ref issue #111.
7ec32b6
Owner
mcdonc commented May 31, 2013

Thank you! I've released Colander 1.0a5 with a fix.l

@mcdonc mcdonc closed this May 31, 2013

Amazing ! Thanks :)

Bad news : I now have a ValueError : https://github.com/spiral-project/daybed/blob/master/daybed/tests/test_types.py#L117

 File "/home/travis/build/spiral-project/daybed/local/lib/python2.7/site-packages/colander-1.0a5-py2.7.egg/colander/iso8601.py", line 148, in parse_date
int(groups["fraction"]), tz)
ValueError: month must be in 1..12

https://travis-ci.org/spiral-project/daybed/jobs/7670050

Owner
mcdonc commented May 31, 2013

I can fix that... what is invalid about this line.. sorry, I can't tell from reading it:

https://github.com/spiral-project/daybed/blob/master/daybed/tests/test_types.py#L119

You're right, it's not very clear to me either.

With colander 1.0a2, I had :

>>> colander.SchemaNode(colander.Date()).deserialize('2012-04-30T13:37Z')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/__init__.py", line 1813, in deserialize
    appstruct = self.typ.deserialize(self, cstruct)
  File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/__init__.py", line 1515, in deserialize
    mapping={'val':cstruct, 'err':e})
colander.Invalid: {'': u'Invalid date'}

Adding seconds seemed to sort this out :

>>> colander.SchemaNode(colander.Date()).deserialize('2012-04-30T13:37:00Z')
datetime.date(2012, 4, 30)

With colander 0.9.9, problem of mandatory seconds for time is the same.

>>> colander.SchemaNode(colander.Date()).deserialize('2012-04-30T13:37Z')
...
colander.Invalid: {'': u'Invalid date'}

>>> colander.SchemaNode(colander.DateTime()).deserialize('2012-04-30T13:37Z')
...
colander.Invalid: {'': u'Invalid date'}
>>> colander.SchemaNode(colander.Date()).deserialize('2012-04-30T13:37:00Z')
datetime.date(2012, 4, 30)

>>> colander.SchemaNode(colander.DateTime()).deserialize('2012-04-30T13:37:00Z')
datetime.datetime(2012, 4, 30, 13, 37, tzinfo=<colander.iso8601.Utc object at 0x7fb2d14a8550>)

Do you want me to open another issue ?

Owner
tseaver commented Jun 3, 2013

@leplatrem: The truncations were fixed in version 1.0a3 -- this bug was about a regression introduced in that fix. The fix for the regression was released in 1.0a5. Please don't open a new issue if you cannot reproduce with 1.0a5.

Ok got it.

Indeed, it's fixed in 1.0.0a5.

So the only problem remaining is about ValueError being raised instead of Invalid for out-of-range errors ( 32th of may )

>>> colander.SchemaNode(colander.Date()).deserialize('2012-03-32')
...
ValueError: day is out of range for month
Owner
tseaver commented Jun 3, 2013

@leplatrem thanks, 5816554 should address that in the next release.

almet commented Jun 7, 2013

Any ETA for the next release?

Django 1.7
help me
When I try
./manage migrate
TypeError: int() argument must be a string or a number, not 'datetime.date'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment