sdementen / piecash

Pythonic interface to GnuCash SQL documents
Other
289 stars 74 forks source link

TZLocal update to 3.0 breaks piecash #180

Closed rerobins closed 3 years ago

rerobins commented 3 years ago

2.1 works fine.

Throws this exception:

 File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/gnucash_reports/wrapper.py", line 241, in get_balance_on_date
    ).order_by(piecash.Price.date.desc()).limit(1).one_or_none()
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3459, in one_or_none
    ret = list(self)
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3535, in __iter__
    return self._execute_and_instances(context)
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3560, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
    return meth(self, multiparams, params)
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1130, in _execute_clauseelement
    distilled_params,
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1207, in _execute_context
    e, util.text_type(statement), parameters, None, None
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1511, in _handle_dbapi_exception
    sqlalchemy_exception, with_traceback=exc_info[2], from_=e
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
    raise exception
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1204, in _execute_context
    context = constructor(dialect, self, conn, *args)
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 854, in _init_compiled
    param.append(processors[key](compiled_params[key]))
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/sqlalchemy/sql/type_api.py", line 1232, in process
    return process_param(value, dialect)
  File "/usr/local/data/laminar/run/accounts_update/1055/accounts/env/lib/python3.7/site-packages/piecash/sa_extra.py", line 140, in process_bind_param
    result = tz.localize(datetime.datetime.combine(value, datetime.time(0, 0, 0))) \
sqlalchemy.exc.StatementError: (builtins.AttributeError) 'backports.zoneinfo.ZoneInfo' object has no attribute 'localize'
[SQL: SELECT prices.value_num AS prices_value_num, prices.value_denom AS prices_value_denom, prices.guid AS prices_guid, prices.commodity_guid AS prices_commodity_guid, prices.currency_guid AS prices_currency_guid, prices.date AS prices_date, prices.source AS prices_source, prices.type AS prices_type 
FROM prices 
WHERE %s = prices.commodity_guid AND %s = prices.currency_guid AND prices.date <= %s ORDER BY prices.date DESC 
 LIMIT %s]
sdementen commented 3 years ago

tx for reporting this issue. could you try changing the line https://github.com/sdementen/piecash/blob/master/piecash/sa_extra.py#L72 by tz = pytz.timezone(str(tzlocal.get_localzone())) with tzlocal=3.0 ?