Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot serialize _CachedRelation #4392

Closed
jtcohen6 opened this issue Dec 2, 2021 · 0 comments · Fixed by #4396
Closed

Cannot serialize _CachedRelation #4392

jtcohen6 opened this issue Dec 2, 2021 · 0 comments · Fixed by #4396
Labels
bug Something isn't working logging

Comments

@jtcohen6
Copy link
Contributor

jtcohen6 commented Dec 2, 2021

Reproduction steps

Run test__postgres__simple_copy_with_materialized_views with JSON-formatted logging:

DBT_LOG_FORMAT=json python3 -m pytest -m profile_postgres test/integration/001_simple_copy_test/test_simple_copy.py::TestSimpleCopy::test__postgres__simple_copy_with_materialized_views 
core/dbt/events/functions.py:208: in create_log_line
    return create_json_log_line(e, msg_fn)  # json output, both console and file
core/dbt/events/functions.py:200: in create_json_log_line
    values = event_to_serializable_dict(e, lambda _: e.get_ts_rfc3339(), lambda x: msg_fn(x))
core/dbt/events/functions.py:139: in event_to_serializable_dict
    for field, value in dataclasses.asdict(e).items():  # type: ignore[attr-defined]
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/dataclasses.py:1073: in asdict
    return _asdict_inner(obj, dict_factory)
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/dataclasses.py:1080: in _asdict_inner
    value = _asdict_inner(getattr(obj, f.name), dict_factory)
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/dataclasses.py:1114: in _asdict_inner
    return copy.deepcopy(obj)
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/copy.py:153: in deepcopy
    y = copier(memo)
core/dbt/adapters/cache.py:82: in __deepcopy__
    new = self.__class__(self.inner.incorporate())
core/dbt/contracts/relation.py:51: in incorporate
    value = self.to_dict(omit_none=True)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <PostgresRelation "dbt"."test16384599476280903696_simple_copy_001"."unrelated_materialized_view">, use_bytes = False, use_enum = False
use_datetime = False

>   ???
E   AttributeError: 'str' object has no attribute '_serialize'

<string>:14: AttributeError

In particular, the AddRelation event (included because --log-cache-events is enabled) has a _CachedRelation object as a dataclass property. This seems like the same issue we were observing in #4361 (comment):

ipdb> dataclasses.asdict(e)
*** AttributeError: 'str' object has no attribute '_serialize'
ipdb> e.__dataclass_fields__
{'relation': Field(name='relation',type=<class 'dbt.events.stubs._CachedRelation'>,default=<dataclasses._MISSING_TYPE object at 0x10a541640>,default_factory=<dataclasses._MISSING_TYPE object at 0x10a541640>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD), 'code': Field(name='code',type=<class 'str'>,default='E024',default_factory=<dataclasses._MISSING_TYPE object at 0x10a541640>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),_field_type=_FIELD)}
@jtcohen6 jtcohen6 added bug Something isn't working logging labels Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working logging
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant