level12 / keg-elements

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

testing_create() fails for a column_property() column

rsyring opened this issue · comments

Given and entity with fields like:

    start_date = sa.Column(sa.Date, nullable=False)
    end_date = sa.orm.column_property(start_date + 6)

Our testing_create() implementation fails at:

Traceback (most recent call last):
  File "/home/rsyring/projects/marshal-src/marsh/tests/test_model_ents.py", line 77, in test_start_date_requires_sunday
    check(arrow.get().shift(weekday=0).date())
  File "/home/rsyring/projects/marshal-src/marsh/tests/test_model_ents.py", line 72, in check
    ents.ApprovalWeek.testing_create(start_date=date)
  File "/home/rsyring/projects/marshal-src/marsh/model/entities.py", line 472, in testing_create
    return super().testing_create(**kwargs)
  File "/home/rsyring/projects/marshal-src/marsh/libs/model.py", line 40, in testing_create
    record = super().testing_create(**entity_kwargs)
  File "/home/rsyring/tmp/virtualenvs/marshal/lib/python3.9/site-packages/keg_elements/db/mixins.py", line 56, in kwargs_match_entity
    return wrapped(*args, **kwargs)
  File "/home/rsyring/tmp/virtualenvs/marshal/lib/python3.9/site-packages/keg_elements/db/mixins.py", line 292, in testing_create
    for column in (col for col in insp.columns if not skippable(col)):
  File "/home/rsyring/tmp/virtualenvs/marshal/lib/python3.9/site-packages/keg_elements/db/mixins.py", line 292, in <genexpr>
    for column in (col for col in insp.columns if not skippable(col)):
  File "/home/rsyring/tmp/virtualenvs/marshal/lib/python3.9/site-packages/keg_elements/db/mixins.py", line 287, in <lambda>
    or column.server_default  # skip fields with server defaults
  File "/home/rsyring/tmp/virtualenvs/marshal/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 854, in __getattr__
    util.raise_(
  File "/home/rsyring/tmp/virtualenvs/marshal/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 207, in raise_
    raise exception
AttributeError: Neither 'Label' object nor 'Comparator' object has an attribute 'server_default'

We should skip column properties since they are read-only by nature. Also, while we are at it move the "skippable" logic to a method that can be overriden for a given class.

My workaround was to set end_date=None in the kwargs for testing_create().