Open fchareyr opened 1 year ago
Thanks for the issue; seems fixable. Similar to #8013 and https://github.com/PrefectHQ/prefect/issues/7508
Hi @fchareyr - thanks for the writeup
To clarify the problem here, these schemas are created by generating a JSON representation of your pydantic models which alone cannot guarantee ordering; JSON is inherently an unordered format and if you're using Postgres it will apply a key-length (!!) sort on your schema on load.
In https://github.com/PrefectHQ/prefect/pull/8013 @j-tr introduced a new position
key to the schemas generated by the parameter schema callable which is used by deployments and flows. A similar position
key on blocks would enable this same behavior; open to opinions / PRs on this though as there might be some block-specific considerations I'm not aware of
And to note: there shouldn't be any UI work involved here since schema form fields already respect the position
key
First check
Bug summary
The order of fields in the Blocks' is not preserved between the code and the UI. As per pydantic documentation:
Reproduction
CustomBlock
class incustom.py
:from prefect.blocks.core import Block from pydantic import Field
class CustomBlock(Block): a: Optional[int] = Field(default=None) b: str = Field(default="abc") c: Optional[str] = Field(default=None)
Error
After the first register, the order of the fields is correct.
After the second register, despite re-arranging the fields in the code, the initial order is preserved.
Browsers
Prefect version
Additional context
No response