From 7223ea3c3f4021e1b9240b586ff371ee75e24e7c Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Sun, 22 Apr 2018 16:27:43 +0100 Subject: [PATCH] Don't explode on invalid dates --- src/documents/models.py | 5 ++++- src/documents/tests/test_consumer.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/documents/models.py b/src/documents/models.py index eb45e5470..e77d5507b 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -394,7 +394,10 @@ class FileInfo(object): @classmethod def _get_created(cls, created): - return dateutil.parser.parse("{:0<14}Z".format(created[:-1])) + try: + return dateutil.parser.parse("{:0<14}Z".format(created[:-1])) + except ValueError: + return None @classmethod def _get_correspondent(cls, name): diff --git a/src/documents/tests/test_consumer.py b/src/documents/tests/test_consumer.py index 9f2445340..93b9aaa5c 100644 --- a/src/documents/tests/test_consumer.py +++ b/src/documents/tests/test_consumer.py @@ -359,3 +359,8 @@ class TestFieldPermutations(TestCase): } self._test_guessed_attributes( template.format(**spec), **spec) + + def test_invalid_date_format(self): + info = FileInfo.from_path("/path/to/06112017Z - title.pdf") + self.assertEqual(info.title, "title") + self.assertIsNone(info.created)