bvanelli / actualpy

Python API implementation for Actual server - reference https://actualbudget.org/
20 stars 4 forks source link

New custom report options are causing an error loading the budget. #39

Closed cgiacofei closed 1 month ago

cgiacofei commented 2 months ago

Checks

Reproducible example

from actual import Actual
from datetime import datetime

with Actual(
    base_url="https://<URL>",
    password="<Password>",
    encryption_password="<Encrypt Password>",
    file="<Budget Name>",
    data_dir="."
) as actual:
    current_date = datetime.now().strftime("%Y%m%d-%H%M")
    actual.export_data(f"actual_backup_{current_date}.zip")

Log output

Traceback (most recent call last):
  File "D:\Shared\Projects\BudgetFiles\test.py", line 4, in <module>
    with Actual(
  File "D:\Shared\Projects\BudgetFiles\venv\Lib\site-packages\actual\__init__.py", line 91, in __enter__
    self.download_budget(self._encryption_password)
  File "D:\Shared\Projects\BudgetFiles\venv\Lib\site-packages\actual\__init__.py", line 322, in download_budget
    self.sync()
  File "D:\Shared\Projects\BudgetFiles\venv\Lib\site-packages\actual\__init__.py", line 352, in sync
    self.apply_changes(changes.get_messages(self._master_key))
  File "D:\Shared\Projects\BudgetFiles\venv\Lib\site-packages\actual\__init__.py", line 272, in apply_changes
    raise ActualError(
actual.exceptions.ActualError: Actual found a column not supported by the library: column 'include_current' at table 'custom_reports' not found

Issue description

Attempting to perform budget backup using the example given in repo as a test. An object of class Actual is not able to be created due to the repo schema not including the new include_current field in custom reports.

Expected behavior

The budget should load.

Installed versions

cgiacofei commented 2 months ago

Adding the column to the CustomReports schema in database.py seems to be all that's needed to fix the error.

class CustomReports(BaseModel, table=True):
    __tablename__ = "custom_reports"

    ...
    include_current: Optional[int] = Field(default=None, sa_column=Column("include_current", Integer))
bvanelli commented 1 month ago

Hello @cgiacofei , thanks for your report, I think I missed this columns because my local docker version was still running an older version of Actual. I added a patch at https://github.com/bvanelli/actualpy/pull/42

I added a test to prevent the model from not being updated in the future, and it complains on the latest version that the column was missing:

image
bvanelli commented 1 month ago

I merged https://github.com/bvanelli/actualpy/pull/42 and you can now install from git.

I would like to do some further testing before generating a new version, feel free to reopen the issue if you still have issues after installing the newest version.