sqlmesh icon indicating copy to clipboard operation
sqlmesh copied to clipboard

AttributeError: 'str' object has no attribute 'is_type'

Open anentropic opened this issue 1 year ago • 3 comments

when running sqlmesh plan I got this error:

AttributeError: 'str' object has no attribute 'is_type'
Error: Failed to resolve macro for expression. Error trying to eval macro.

if I stick a breakpoint in I find:

sqlmesh/utils/__init__.py(330)type_is_known()
-> raise
(Pdb++) l
325  	    try:
326  	        if d_type.is_type(exp.DataType.Type.UNKNOWN, exp.DataType.Type.NULL):
327  	            return False
328  	    except:
329  	        breakpoint()
330  ->	        raise
331  	    if d_type.expressions:
332  	        return all(type_is_known(expression) for expression in d_type.expressions)
333  	    return True
334
335
(Pdb++) d_type
'UNKNOWN'

the offending code in my model file is here:

select
    @STAR(order_dedup)
from order_dedup
where
    snowflake_last_ingested_at between @start_ts and @end_ts

where order_dedup is a View model, perhaps that is the problem (?)

However if I amend the error handling code to:

        if d_type == 'UNKNOWN' or d_type.is_type(exp.DataType.Type.UNKNOWN, exp.DataType.Type.NULL):
            return False

then the plan succeeds and I get the option to apply it

anentropic avatar May 13 '24 16:05 anentropic

Hey @anentropic, thanks for the report. Can you share the full stack trace? How do you reach sqlmesh/utils/__init__.py(330)type_is_known()?

georgesittas avatar May 13 '24 16:05 georgesittas

Nvm, I think I see the issue. Will fix shortly.

georgesittas avatar May 13 '24 16:05 georgesittas

the stack trace was:

  File "/Users/anentropic/dev/etl-future/.venv/lib/python3.11/site-packages/sqlmesh/core/macros.py", line 214, in send
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/anentropic/dev/etl-future/.venv/lib/python3.11/site-packages/sqlmesh/core/macros.py", line 834, in star
    if columns_to_types_all_known(columns_to_types):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/anentropic/dev/etl-future/.venv/lib/python3.11/site-packages/sqlmesh/utils/__init__.py", line 334, in columns_to_types_all_known
    return all(type_is_known(expression) for expression in columns_to_types.values())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/anentropic/dev/etl-future/.venv/lib/python3.11/site-packages/sqlmesh/utils/__init__.py", line 334, in <genexpr>
    return all(type_is_known(expression) for expression in columns_to_types.values())
               ^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/anentropic/dev/etl-future/.venv/lib/python3.11/site-packages/sqlmesh/utils/__init__.py", line 325, in type_is_known
    if d_type.is_type(exp.DataType.Type.UNKNOWN, exp.DataType.Type.NULL):
       ^^^^^^^^^^^^^^

anentropic avatar May 13 '24 16:05 anentropic