Unmanic / unmanic

Unmanic - Library Optimiser
GNU General Public License v3.0
1.41k stars 84 forks source link

In session.py "unsupported operand type(s) for +: 'datetime.datetime' and 'int'" logged on startup and on library scan #469

Closed rjclark closed 1 month ago

rjclark commented 1 month ago

Description

On startup, and when forcing a library scan, the follow error message is displayed and the scan does not complete

2024-03-24T20:16:20:ERROR:Unmanic.LibraryScannerManager - [FORMATTED] - Exception in retrieving library scanner trigger LibraryScannerManager: - unsupported operand type(s) for +: 'datetime.datetime' and 'int'
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/unmanic/libs/libraryscanner.py", line 121, in run
    self.scheduled_job()
  File "/usr/local/lib/python3.10/dist-packages/unmanic/libs/libraryscanner.py", line 152, in scheduled_job
    if not self.system_configuration_is_valid():
  File "/usr/local/lib/python3.10/dist-packages/unmanic/libs/libraryscanner.py", line 187, in system_configuration_is_valid
    if not Library.within_library_count_limits(self.data_queues.get('frontend_messages')):
  File "/usr/local/lib/python3.10/dist-packages/unmanic/libs/library.py", line 153, in within_library_count_limits
    s.register_unmanic()
  File "/usr/local/lib/python3.10/dist-packages/unmanic/libs/session.py", line 455, in register_unmanic
    if not force and self.__check_session_valid():
  File "/usr/local/lib/python3.10/dist-packages/unmanic/libs/session.py", line 146, in __check_session_valid
    if not self.__created_older_than_x_days(days=2):
  File "/usr/local/lib/python3.10/dist-packages/unmanic/libs/session.py", line 122, in __created_older_than_x_days
    time_when_session_expires = self.created + seconds
TypeError: unsupported operand type(s) for +: 'datetime.datetime' and 'int'

Steps to Reproduce

Using the josh5/unmanic:latest Docker image, started like this:

docker run \
    --name unmanic \
    --rm \
    -e PUID=${PUID} \
    -e PGID=${PGID} \
    -e TZ=Americas/Toronto \
    -e DEBUGGING=true \
    -e NUMBER_OF_WORKERS=2 \
    -p 8888:8888 \
    -v ${CONFIG_DIR}:/config \
    -v ${LIBRARY_DIR}:/library \
    -v ${CACHE_DIR}:/tmp/unmanic \
    josh5/unmanic:latest

I'm wondering if the code in the libs/session.py library (line 167) is setting a class variable.

# Print only the accurate update time in debug log
from datetime import datetime
created = datetime.fromtimestamp(seconds)
# ^^^^^^ line 167
self.logger.debug('Updated session at %s', str(created))

A quick hack to change the variable name seems to have worked.

x_created = datetime.fromtimestamp(seconds)
self.logger.debug('Updated session at %s', str(x_created))

I'll admit I'm not a Python expert, but that the first time I've run across a conflict between a local and class variable.

Josh5 commented 1 month ago

This should be fixed with commit a6a30c429c7e1c20816a8dd04b00149c9e21574a

Thanks