Skip to content

Failed to load json_data to dataclass - #684

Merged
wild-endeavor merged 4 commits into
masterfrom
Fix-dataclass
Oct 6, 2021
Merged

wild-endeavor merged 4 commits into
masterfrom
Fix-dataclass

Conversation

@pingsutw

@pingsutw pingsutw commented Oct 1, 2021

Copy link
Copy Markdown
Member

Signed-off-by: Kevin Su pingsutw@apache.org

TL;DR

Fix errors in feast notebook.
Before

>>> print(feature_store)
>>> print(feature_store.config)

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)

/var/folders/by/42kc70lj1bb77klbhf2fmxx00000gn/T/ipykernel_46553/3923996928.py in <module>
      1 print(feature_store)
----> 2 print(feature_store.config)
      3 

~/opt/anaconda3/envs/flyte/lib/python3.8/site-packages/flytekit/core/type_engine.py in __getattr__(self, key)
    766                 return self.__getitem__(key)
    767             except KeyError:
--> 768                 raise AttributeError(key)
    769 
    770     return dataclass_json(dataclasses.dataclass(Model))

AttributeError: config

After
https://github.com/pingsutw/flytesnacks/blob/interactive-feast/cookbook/case_studies/feature_engineering/feast_integration/Feast_Flyte_Demo.ipynb

The problem is that we didn't set the attribute for model class, so we can't load json_data to dataclass

dc = cast(DataClassJsonMixin, expected_python_type).from_json(_json_format.MessageToJson(lv.scalar.generic))

For example:

@dataclass_json
@dataclass()
class Bar(object):
    x: float
    y: str

We have to set attributes x and y for the model class when we guess data type. otherwise, TypeEngine will keep failing to translate Literal to python value

Type

  • Bug Fix
  • Feature
  • Plugin

Are all requirements met?

  • Code completed
  • Smoke tested
  • Unit tests added
  • Code documentation added
  • Any pending items have an associated Issue

Complete description

How did you fix the bug, make the feature etc. Link to any design docs etc

Tracking Issue

https://github.com/lyft/flyte/issues/

Follow-up issue

NA

Signed-off-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: Kevin Su <pingsutw@apache.org>
@codecov

codecov Bot commented Oct 1, 2021

Copy link
Copy Markdown

Codecov Report

Merging #684 (c0922b3) into master (7421be2) will increase coverage by 0.04%.
The diff coverage is 97.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #684      +/-   ##
==========================================
+ Coverage   85.65%   85.69%   +0.04%     
==========================================
  Files         355      355              
  Lines       29661    29683      +22     
  Branches     2415     2425      +10     
==========================================
+ Hits        25406    25438      +32     
+ Misses       3615     3604      -11     
- Partials      640      641       +1     
Impacted Files Coverage Δ
flytekit/core/type_engine.py 88.36% <95.55%> (+0.54%) ⬆️
tests/flytekit/unit/core/test_type_engine.py 99.71% <100.00%> (+0.01%) ⬆️
flytekit/remote/remote.py 73.25% <0.00%> (-0.20%) ⬇️
flytekit/core/base_task.py 89.04% <0.00%> (ø)
flytekit/remote/workflow_execution.py 89.18% <0.00%> (+16.46%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7421be2...c0922b3. Read the comment docs.

Signed-off-by: Kevin Su <pingsutw@apache.org>
@pingsutw pingsutw changed the title Update convert_json_schema_to_python_class Failed to load json_data to dataclass Oct 1, 2021
@wild-endeavor

Copy link
Copy Markdown
Contributor

cc @eapolinario

This PR doesn't fully deprecate https://github.com/flyteorg/flytekit/pull/675/files right? Should we merge that one in first?

For this PR, can we add a unit test that calls to TypeEngine.dict_to_literal_map like this

assert TypeEngine.dict_to_literal_map(ctx, python_value, python_types) == expected_literal_map

@eapolinario

Copy link
Copy Markdown
Collaborator

This PR doesn't fully deprecate https://github.com/flyteorg/flytekit/pull/675/files right? Should we merge that one in first?

Correct, it doesn't, although we could merge this PR first and let #675 be only about handling the inputs+outputs in flyteremote. What do you think, @wild-endeavor ?

@wild-endeavor

Copy link
Copy Markdown
Contributor

yeah that sounds good. let's still add that dict_to_literal_map unit test to this PR though, then +1

Signed-off-by: Kevin Su <pingsutw@apache.org>
@wild-endeavor
wild-endeavor merged commit 243adb7 into master Oct 6, 2021
eapolinario pushed a commit that referenced this pull request Oct 8, 2021
Signed-off-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
AdrianoKF pushed a commit to AdrianoKF/flytekit that referenced this pull request Oct 11, 2021
Signed-off-by: Kevin Su <pingsutw@apache.org>
eapolinario added a commit that referenced this pull request Oct 19, 2021
* Run 3.9 in CI

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Also run 3.9 in plugins tests.

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Fix tests

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Account for the different exception type raised in case of wrong types

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Exclude spark2

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Failed to load json_data to dataclass (#684)

Signed-off-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Remove sync singledispatch, add option for top-level only sync (#681)

Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Failed to transform path string to Literal (#689)

Signed-off-by: Kevin Su <pingsutw@apache.org>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Don't node sync on remote wait (#690)

* no node sync

Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>

* add param to wait

Signed-off-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>
Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Fix plugin regressions (#688)

* fix pandera regression

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* install plugin with pip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* fix pandera plugin tests

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* wip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* wip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* wip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* wip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* wip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* wip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* add spark flytekit plugin to papermill test_requires

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* wip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* wip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* wip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* wip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* add sqlalchemy to great expectations plugin

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* wip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* wip

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* plugins plugins plugins!

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* lint

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

* Exclude does not understand lists

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Invert python version check

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Invert python version check for real this time

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Enable 3.10 just for kicks

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Add quotes around python versions

Yes, this is needed, please see https://dev.to/hugovk/the-python-3-1-problem-85g.

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Revert "Add quotes around python versions"

This reverts commit 4d619d5.

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Revert "Enable 3.10 just for kicks"

This reverts commit bd6d694.

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* wip - restricted types

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* wip - restricted types

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Comment use of restricted types in get_transformer

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Publish 3.9 image

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Add python 3.9 to the list of supported languages

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Comment RestrictedTypeTransformer and add one test case.

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Review feedback

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Comment RestrictedTypeTransformer

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Handle the TypeError

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

* Remove breakpoint

Signed-off-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>

Co-authored-by: Eduardo Apolinario <eapolinario@users.noreply.github.com>
Co-authored-by: Kevin Su <pingsutw@gmail.com>
Co-authored-by: Yee Hing Tong <wild-endeavor@users.noreply.github.com>
Co-authored-by: Niels Bantilan <niels.bantilan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants