linuxsoftware / ls.joyous

A calendar application for Wagtail
BSD 3-Clause "New" or "Revised" License
74 stars 35 forks source link

Joyous raises error with Django 3.2.17 Wagtail 2.16.3 and Python 3.9 #51

Closed dennereed closed 1 year ago

dennereed commented 1 year ago

Installation works but raises error at runtime. Traceback below File "/Users/dreed/Documents/pycharm/paleocore-lite/venv/lib/python3.9/site-packages/ls/joyous/models/init.py", line 12, in from .recurring_events import RecurringEventPage File "/Users/dreed/Documents/pycharm/paleocore-lite/venv/lib/python3.9/site-packages/ls/joyous/models/recurring_events.py", line 40, in from ..holidays import Holidays File "/Users/dreed/Documents/pycharm/paleocore-lite/venv/lib/python3.9/site-packages/ls/joyous/holidays/init.py", line 8, in from .parser import parseHolidays File "/Users/dreed/Documents/pycharm/paleocore-lite/venv/lib/python3.9/site-packages/ls/joyous/holidays/parser.py", line 21, in _PYTHON_HOLIDAYS_MAP = _createMap(list(python_holidays.dict.items())) File "/Users/dreed/Documents/pycharm/paleocore-lite/venv/lib/python3.9/site-packages/ls/joyous/holidays/parser.py", line 17, in _createMap obj = cls() TypeError: init() missing 2 required positional arguments: 'h1' and 'h2' make: *** [migrate] Error 1

This error may stem from a revision to the Python holiday library. The error arises because the base class HolidaySum is not removed from holidayMap list, and HolidaySum takes two required arguments on initialization. The error arises in ls.joyous.holidays.parser, specifically line 17 in the _createMap function where there is an attempt to create an instance of a class with the call obj = cls(). This works for most of the classes that are iterated in the function except for the base class and some other exceptions. A fix is to add in one additional condition to the if clause. Revising the function like this works.

def _createMap(symbols):
    holidayMap = {}
    for (name, cls) in symbols:
        if (type(cls) is type(object) and
            issubclass(cls, python_holidays.HolidayBase) and
            cls is not python_holidays.HolidayBase and cls is not python_holidays.HolidaySum):
            holidayMap[name] = cls
            obj = cls()
            if hasattr(obj, "country"):
                holidayMap.setdefault(obj.country, cls)
    return holidayMap 
dennereed commented 1 year ago

Never mind :-) The issue is only with the current PyPi package (v 1.4.0) The current GitHub version fixes the problem. Looks like were just waiting for the PyPi package to get updated. Thanks!