ixc / python-edtf

MIT License
53 stars 19 forks source link

Django 4.2 & Python 3.11 compatibility #41

Closed krzysztofjeziorny closed 3 months ago

krzysztofjeziorny commented 1 year ago

Being not that fluent in Python I can't say if I'm doing something wrong or it's a plain incompatibility of this app with Django 4.2 and Python 3.11.5 (or Wagtail CMS in my case).

My fields (as in the readme example) implemented in Wagtail's 5.1.2 model:

    date_display = models.CharField(
        _("Date (display)"),
        blank=True,
        max_length=255,
    )
    date_edtf = EDTFField(
        _("Date (EDTF)"),
        natural_text_field="date_display",
        lower_fuzzy_field="date_earliest",
        upper_fuzzy_field="date_latest",
        lower_strict_field="date_sort_ascending",
        upper_strict_field="date_sort_descending",
        blank=True,
        null=True,
    )
    # use for filtering
    date_earliest = models.FloatField(blank=True, null=True)
    date_latest = models.FloatField(blank=True, null=True)
    # use for sorting
    date_sort_ascending = models.FloatField(blank=True, null=True)
    date_sort_descending = models.FloatField(blank=True, null=True)

when filled the date_edtf field with value (let's say 1800 or 'Fall 1989') I get a TypeError: object of type 'Unspecified' has no len().

Thanks for any hints.

Full error
127.0.0.1 - - [29/Sep/2023 11:08:40] "POST /verwaltung/pages/17/edit/ HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/contrib/staticfiles/handlers.py", line 80, in __call__
    return self.application(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/core/handlers/wsgi.py", line 124, in __call__
    response = self.get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/core/handlers/base.py", line 140, in get_response
    response = self._middleware_chain(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/core/handlers/exception.py", line 57, in inner
    response = response_for_exception(request, exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/core/handlers/exception.py", line 140, in response_for_exception
    response = handle_uncaught_exception(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/core/handlers/exception.py", line 181, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django_extensions/management/technical_response.py", line 40, in null_technical_500_response
    raise exc_value.with_traceback(tb)
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/views/decorators/cache.py", line 62, in _wrapper_view_func
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/wagtail/admin/urls/__init__.py", line 180, in wrapper
    return view_func(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/wagtail/admin/auth.py", line 165, in decorated_view
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/wagtail/admin/views/pages/edit.py", line 386, in dispatch
    return super().dispatch(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/wagtail/admin/views/pages/edit.py", line 469, in post
    if self.form.is_valid() and not self.locked_for_user:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/wagtail/admin/forms/pages.py", line 179, in is_valid
    return super().is_valid()
           ^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/modelcluster/forms.py", line 343, in is_valid
    form_is_valid = super().is_valid()
                    ^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/forms/forms.py", line 201, in is_valid
    return self.is_bound and not self.errors
                                 ^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/forms/forms.py", line 196, in errors
    self.full_clean()
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/forms/forms.py", line 435, in full_clean
    self._post_clean()
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/forms/models.py", line 486, in _post_clean
    self.instance.full_clean(exclude=exclude, validate_unique=False)
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/wagtail/models/__init__.py", line 1373, in full_clean
    super().full_clean(*args, **kwargs)
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/db/models/base.py", line 1470, in full_clean
    self.clean_fields(exclude=exclude)
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/db/models/base.py", line 1522, in clean_fields
    setattr(self, f.attname, f.clean(raw_value, self))
                             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/db/models/fields/__init__.py", line 778, in clean
    self.run_validators(value)
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/db/models/fields/__init__.py", line 730, in run_validators
    v(value)
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/core/validators.py", line 366, in __call__
    cleaned = self.clean(value)
              ^^^^^^^^^^^^^^^^^
  File "/Users/kj/Library/Python/3.11/lib/python/site-packages/django/core/validators.py", line 450, in clean
    return len(x)
           ^^^^^^
TypeError: object of type 'Unspecified' has no len()
aweakley commented 3 months ago

This is resolved by #56