fractal-analytics-platform / fractal-client

Command-line client for Fractal
https://fractal-analytics-platform.github.io/fractal-client
BSD 3-Clause "New" or "Revised" License
45 stars 1 forks source link

Error in Task class with sqlmodel=0.0.7 #147

Closed tcompa closed 2 years ago

tcompa commented 2 years ago

By requiring sqlmodel >=0.0.7, we may use this bugfix - and remove our custom workaround from https://github.com/fractal-analytics-platform/fractal/blob/6b7b3e08875729c32f930a478d545c5ddb382142/fractal/server/app/models/security.py#L22-L36

Version 0.0.7 should be available as of today. To be tested.

tcompa commented 2 years ago

Updating sqlmodel requires adapting to this new PR: Raise an exception when using a Pydantic field type with no matching SQLAlchemy type.

More in detail, right now (after installing sqlmodel=0.0.7), we have that

poetry run python fractal/server/app/models/task.py

fails with

Traceback (most recent call last):
  File "fractal/server/app/models/task.py", line 103, in <module>
    class Task(TaskBase, table=True):  # type: ignore
  File "/home/tommaso/miniconda3/envs/fractal/lib/python3.8/site-packages/sqlmodel/main.py", line 293, in __new__
    col = get_column_from_field(v)
  File "/home/tommaso/miniconda3/envs/fractal/lib/python3.8/site-packages/sqlmodel/main.py", line 421, in get_column_from_field
    sa_type = get_sqlachemy_type(field)
  File "/home/tommaso/miniconda3/envs/fractal/lib/python3.8/site-packages/sqlmodel/main.py", line 414, in get_sqlachemy_type
    raise ValueError(f"The field {field.name} has no matching SQLAlchemy type")
ValueError: The field subtask_list has no matching SQLAlchemy type
jacopo-exact commented 2 years ago

looks to me like a bug from upstream. will investigate further.

jacopo-exact commented 2 years ago

it is an edge case: we need to make sure that base models do not contain mapper members (class members that only exist because of some relationship and get filled up by the ORM but do not exist in the db schema).

I already have a mostly working patch, that fails a test because of how the test is written, rather than because of this issue.

tcompa commented 2 years ago

Great. Feel free to include it in PR https://github.com/fractal-analytics-platform/fractal/pull/151