OurchiveIO / ourchive

An easily installable fiction, audio, and image archive package.
GNU General Public License v3.0
7 stars 6 forks source link

Works imported from AO3 cannot be displayed #142

Closed bellisk closed 2 months ago

bellisk commented 2 months ago

Describe the bug Going to the url of a work imported from AO3 gives an error page. The following error is logged:

django.request ERROR 2024-04-24 13:51:06,149 log 116173 139814288162880 Internal Server Error: /works/52/
Traceback (most recent call last):
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/django/views/decorators/http.py", line 64, in inner
    return func(request, *args, **kwargs)
  File "/home/ourchive/ourchive/ourchive_app/frontend/views.py", line 1230, in work
    chapter = format_date_for_template(chapter, 'updated_on')
  File "/home/ourchive/ourchive/ourchive_app/frontend/view_utils.py", line 331, in format_date_for_template
    obj[field_name] = parse(obj[field_name]).date()
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/dateutil/parser/_parser.py", line 1368, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/dateutil/parser/_parser.py", line 640, in parse
    res, skipped_tokens = self._parse(timestr, **kwargs)
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/dateutil/parser/_parser.py", line 719, in _parse
    l = _timelex.split(timestr)         # Splits the timestr into tokens
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/dateutil/parser/_parser.py", line 201, in split
    return list(cls(s))
  File "/home/ourchive/ourchive/virtualenv/lib/python3.10/site-packages/dateutil/parser/_parser.py", line 69, in __init__
    raise TypeError('Parser must be a string or character stream, not '

What's happening is that formatting the chapter updated_on date for the template is failing, because the chapter has a value of None for that field. The work has a value for updated_on - it's just the chapter that doesn't. Looking in the ETL code a bit, I think that we just can't get an updated date for individual chapters from the AO3 data, so it never gets mapped. In that case, it shouldn't be required to display the chapter or its work.

I will submit a PR to ignore the chapter updated_on if we don't have it, so that the work can be shown. If I'm wrong and this should rather be fixed in the AO3 importer, I can do that instead. :)

To Reproduce

  1. Import one or more works from AO3
  2. Go to a work page, e.g. http://example.org/works/1
  3. See an error page instead of the work contents
  4. Get the work's chapters from the Ourchive API, e.g. http://example.org/api/works/1/chapters/
  5. See that all of the chapters have "updated_on": null

Expected behavior Opening the url of a work should display the work.

Desktop (please complete the following information):

Hosting Digital Ocean droplet running Ubuntu 22.04.