diff --git a/api/funkwhale_api/music/metadata.py b/api/funkwhale_api/music/metadata.py index d22f637fd1f29d65cbbeabb97143dfc6bba10077..9b3b6a387c893e63a1a144efa3f6bde7c12247a0 100644 --- a/api/funkwhale_api/music/metadata.py +++ b/api/funkwhale_api/music/metadata.py @@ -556,7 +556,7 @@ class PermissiveDateField(serializers.CharField): try: parsed = pendulum.parse(str(value)) return datetime.date(parsed.year, parsed.month, parsed.day) - except pendulum.exceptions.ParserError: + except (pendulum.exceptions.ParserError, ValueError): pass return None diff --git a/api/tests/music/test_metadata.py b/api/tests/music/test_metadata.py index 6c9b0384685ce114e07444cc192f0b4d32145a3e..f6aa513ab97c674f2f9a33c150b204e523dc4ef4 100644 --- a/api/tests/music/test_metadata.py +++ b/api/tests/music/test_metadata.py @@ -239,6 +239,7 @@ def test_can_get_metadata_from_flac_file_not_crash_if_empty(): ("2017-12-31", datetime.date(2017, 12, 31)), ("2017-14-01 01:32", datetime.date(2017, 1, 14)), # deezer format ("2017-02", datetime.date(2017, 1, 1)), # weird format that exists + ("0000", None), ("nonsense", None), ], ) diff --git a/changes/changelog.d/966.bugfix b/changes/changelog.d/966.bugfix new file mode 100644 index 0000000000000000000000000000000000000000..c3718fcb6c8c6ed39cfa49597ca75e4565367b4d --- /dev/null +++ b/changes/changelog.d/966.bugfix @@ -0,0 +1 @@ +More robust importer against malformed dates (#966)