Skip to content

Import breaks on invalid metadata #98

@bobobo1618

Description

@bobobo1618

Describe the bug
When invalid metadata is encountered, an exception is thrown and the entire scanning process crashes.

To Reproduce
Steps to reproduce the behavior:

  1. Have a photo with "invalid" metadata (in my case, a timezone in one of the date fields)
  2. Run Photonix
  3. Encounter ValueError: unconverted data remains: +01:00, leading to exited: rescan_photos_periodically (exit status 1; not expected)

Expected behavior
Invalid metadata is ignored and scan continues.

Additional context

Logs:

photonix    | 2019-10-19 13:54:00,463 INFO spawned: 'rescan_photos_periodically' with pid 239
photonix    | Traceback (most recent call last):
photonix    |   File "/srv/photonix/manage.py", line 22, in <module>
photonix    |     execute_from_command_line(sys.argv)
photonix    |   File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
photonix    |     utility.execute()
photonix    |   File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
photonix    |     self.fetch_command(subcommand).run_from_argv(self.argv)
photonix    |   File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
photonix    |     self.execute(*args, **cmd_options)
photonix    |   File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
photonix    |     output = self.handle(*args, **options)
photonix    |   File "/srv/photonix/photos/management/commands/rescan_photos_periodically.py", line 27, in handle
photonix    |     self.rescan_photos(options['paths'])
photonix    |   File "/srv/photonix/photos/management/commands/rescan_photos_periodically.py", line 22, in rescan_photos
photonix    |     import_photos_in_place(path)
photonix    |   File "/srv/photonix/photos/utils/organise.py", line 175, in import_photos_in_place
photonix    |     modified = record_photo(filepath)
photonix    |   File "/srv/photonix/photos/utils/db.py", line 24, in record_photo
photonix    |     date_taken = parse_datetime(metadata.get('Date/Time Original'))
photonix    |   File "/srv/photonix/photos/utils/metadata.py", line 27, in parse_datetime
photonix    |     return datetime.strptime(date_str, '%Y:%m:%d %H:%M:%S').replace(tzinfo=utc)
photonix    |   File "/usr/local/lib/python3.6/_strptime.py", line 565, in _strptime_datetime
photonix    |     tt, fraction = _strptime(data_string, format)
photonix    |   File "/usr/local/lib/python3.6/_strptime.py", line 365, in _strptime
photonix    |     data_string[found.end():])
photonix    | ValueError: unconverted data remains: +01:00
photonix    | 2019-10-19 13:55:01,653 INFO exited: rescan_photos_periodically (exit status 1; not expected)
photonix    | 2019-10-19 13:55:02,654 INFO gave up: rescan_photos_periodically entered FATAL state, too many start retries too quickly

I think there should be a catchall somewhere in this stack which should log the error instead of crashing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions