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

Dependency on import order in user-code #15957

Open
cicdw opened this issue Nov 8, 2024 · 0 comments
Open

Dependency on import order in user-code #15957

cicdw opened this issue Nov 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@cicdw
Copy link
Member

cicdw commented Nov 8, 2024

Bug summary

The following code errors out:

from prefect.states import State
State(type="CANCELLED").to_state_create()

with traceback:

---------------------------------------------------------------------------
PydanticUserError                         Traceback (most recent call last)
Cell In[1], line 2
      1 from prefect.states import State
----> 2 State(type="CANCELLED").to_state_create()

File ~/dev/prefect/src/prefect/client/schemas/objects.py:335, in State.to_state_create(self)
    332 else:
    333     data = None
--> 335 return StateCreate(
    336     type=self.type,
    337     name=self.name,
    338     message=self.message,
    339     data=data,
    340     state_details=self.state_details,
    341 )

    [... skipping hidden 1 frame]

File ~/miniconda3/envs/prefect/lib/python3.10/site-packages/pydantic/_internal/_mock_val_ser.py:47, in MockValSer.__getattr__(self, item)
     45 # raise an AttributeError if `item` doesn't exist
     46 getattr(self._val_or_ser, item)
---> 47 raise PydanticUserError(self._error_message, code=self._code)

PydanticUserError: `StateCreate` is not fully defined; you should define all referenced types, then call `StateCreate.model_rebuild()`.

For further information visit https://errors.pydantic.dev/2.7/u/class-not-fully-defined

It can be resolved by importing anything from the main prefect module:

from prefect import State # any other object would work too

State(type="CANCELLED").to_state_create() # ✅

Version info

Version:             3.1.1.dev6+1.g2624409ffc
API version:         0.8.4
Python version:      3.10.13
Git commit:          2624409f
Built:               Fri, Nov 8, 2024 8:12 AM
OS/Arch:             darwin/arm64
Profile:             ephemeral
Server type:         ephemeral
Pydantic version:    2.7.1
Server:
  Database:          sqlite
  SQLite version:    3.41.2
Integrations:
  prefect-aws:       0.5.0

Additional context

This is related to our known circular import problems; I'm opening this for other users who may be searching with this error message.

@cicdw cicdw added the bug Something isn't working label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant