Prometeo-Pyrrha icon indicating copy to clipboard operation
Prometeo-Pyrrha copied to clipboard

Fix issue where run_analytics() caches the timestamp key, causing Duplicate Record exceptions

Open JSegrave-IBM opened this issue 5 years ago • 0 comments

run_analytics() in GasExposureAnalytics.py is caching the timestamp key after the first time it's called, causing Duplicate Record exceptions on subsequent calls.

Root cause : there's a default argument in the method definition. Python default arguments are evaluated once when the function is defined, not each time the function is called. Hence the caching.

Also fixed in this PR:

  • Add some defensive code around the timestamp key, to ensure it's always (a) in UTC time and (b) does not have a timezone suffix (because mariadb does not support timezone aware timestamp datatypes).
  • Get the logging to respect the LOGLEVEL environment variable and consistently log against the filename, even if it changes (i.e. get rid of the hardcoded log names)

JSegrave-IBM avatar Nov 02 '20 23:11 JSegrave-IBM