sqlmesh run command throws `AttributeError: 'list' object has no attribute 'transform'`
slqmesh run command throws the below error, whereas sqlmesh plan --run command works. Why am I getting this error?
Traceback (most recent call last):
File ".venv/bin/sqlmesh", line 8, in <module>
sys.exit(cli())
^^^^^
File ".venv/lib/python3.11/site-packages/click/core.py", line 1161, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/click/core.py", line 1082, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/click/core.py", line 1697, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/click/core.py", line 1443, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/click/core.py", line 788, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context(), *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/cli/__init__.py", line 31, in wrapper
return handler(sqlmesh_context, lambda: func(*args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/cli/__init__.py", line 40, in _default_exception_handler
return func()
^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/cli/__init__.py", line 31, in <lambda>
return handler(sqlmesh_context, lambda: func(*args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/core/analytics/__init__.py", line 82, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/cli/main.py", line 475, in run
completion_status = context.run(environment, select_models=select_models, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/core/analytics/__init__.py", line 110, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/core/context.py", line 635, in run
self._run_janitor()
File ".venv/lib/python3.11/site-packages/sqlmesh/core/context.py", line 2137, in _run_janitor
expired_snapshots = self.state_sync.delete_expired_snapshots(ignore_ttl=ignore_ttl)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/core/state_sync/cache.py", line 117, in delete_expired_snapshots
return self.state_sync.delete_expired_snapshots(ignore_ttl=ignore_ttl)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/core/state_sync/common.py", line 72, in wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/core/state_sync/engine_adapter.py", line 568, in delete_expired_snapshots
snapshots = self._get_snapshots_with_same_version(versions_batch)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/core/state_sync/engine_adapter.py", line 934, in _get_snapshots_with_same_version
return [
^
File ".venv/lib/python3.11/site-packages/sqlmesh/core/state_sync/engine_adapter.py", line 935, in <listcomp>
Snapshot(
File ".venv/lib/python3.11/site-packages/pydantic/main.py", line 214, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/utils/pydantic.py", line 203, in wrapper
return func(cls, v, values_dict, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/core/model/kind.py", line 990, in _model_kind_validator
return create_model_kind(v, dialect, {})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/core/model/kind.py", line 981, in create_model_kind
return kind_type(**props)
^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/pydantic/main.py", line 214, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/utils/pydantic.py", line 203, in wrapper
return func(cls, v, values_dict, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/sqlmesh/core/model/kind.py", line 467, in _when_matched_validator
return t.cast(exp.Whens, v.transform(d.replace_merge_table_aliases))
^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'transform'
Hey @lafirm, what sqlmesh version are you using? Can you share the result of pip show sqlmesh? Additionally, if you query your state's versions table, what do you see? E.g. in duckdb that would look like:
D from sqlmesh._versions;
┌────────────────┬─────────────────┬─────────────────┐
│ schema_version │ sqlglot_version │ sqlmesh_version │
│ int32 │ varchar │ varchar │
├────────────────┼─────────────────┼─────────────────┤
│ 66 │ 26.2.1 │ 0.148.0 │
└────────────────┴─────────────────┴─────────────────┘
sure, here you go!
Hey @lafirm, what sqlmesh version are you using?
| schema_version | sqlglot_version | sqlmesh_version |
|---|---|---|
| 66 | 26.0.1 | 0.144.0 |
Can you share the result of
pip show sqlmesh?
Name: sqlmesh
Version: 0.144.0
Summary:
Home-page: https://github.com/TobikoData/sqlmesh
Author: TobikoData Inc.
Author-email: [email protected]
License: Apache License 2.0
Location: ****/.venv/lib/python3.11/site-packages
Requires: astor, click, croniter, dateparser, duckdb, hyperscript, importlib-metadata, ipywidgets, jinja2, pandas, pydantic, requests, rich, ruamel.yaml, sqlglot, tenacity, time-machine
Required-by:
Most of our snapshots had when_matched stored as a string, when they should be exp.Whens then it was a string with parenthesis. When the janitor process tries to parse these then it fails as we have list objects still.
I noticed this refactor that was published as part of v0.140.0 https://github.com/TobikoData/sqlmesh/pull/3497/
Looking through the refactor it should have been caught by this migration https://github.com/TobikoData/sqlmesh/blob/main/sqlmesh/migrations/v0064_join_when_matched_strings.py#L49-L50
In which case I'm wondering if they were somehow created with lists after the migration took place... I made a local change which unblocked the janitor process, I'll open up a PR with it on shortly.
Appreciate you looking into this @MikeWallis42, will take a look at the PR once it's up.
In which case I'm wondering if they were somehow created with lists after the migration took place... I made a local change which unblocked the janitor process, I'll open up a PR with it on shortly.
Yeah... I'm not sure how lists could end up being migrated over untouched, the script should convert them into strings, as you've pointed out.
@tobymao any ideas about this one?