-
Notifications
You must be signed in to change notification settings - Fork 6
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
Port to pydantic 2 #192
Port to pydantic 2 #192
Conversation
@@ -98,15 +98,18 @@ async def inbound_message_hook(self, contents: str) -> RTUResponse: | |||
if isinstance(rtu_event, NewDeltaEvent): | |||
extra_dict["delta_type"] = rtu_event.data.delta_type | |||
extra_dict["delta_action"] = rtu_event.data.delta_action | |||
logger.debug(f"Received: {data}\nParsed: {rtu_event.dict()}", extra=extra_dict) | |||
|
|||
if logging.DEBUG >= logging.root.level: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make the logging call that includes dumping the model if our current logging level is lower than DEBUG.
origami/clients/rtu.py
Outdated
# callback function should be async and expect one argument: a FileDelta | ||
# Doesn't matter what it returns. Pydantic doesn't validate Callable args/return. | ||
delta_class: Type[FileDelta] | ||
fn: Callable[[FileDelta], Awaitable[None]] | ||
|
||
def __init__(self, delta_class: Type[FileDelta], fn: Callable[[FileDelta], Awaitable[None]]): | ||
# With pydantic2, raises: "TypeError: Subscripted generics cannot be used with class and instance checks" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to comment out this well meaning check, 'cause pydantic 2 base implementation using parameterized types is incompatible with issubclass
.
Would happily be open to suggestion on respelling it to pivot off of, say, a constant in the class or something to get the same effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to pair with you on this to better understand what's hpapening
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, whenevs. If left in, the isinstance() check now raises an exception 'cause isinstance() can't be used with parameterized types.
|
||
|
||
class BooleanReplyData(BaseModel): | ||
# Gate will reply to most RTU requests with an RTU reply that's just success=True/False | ||
success: bool | ||
|
||
|
||
class BaseRTURequest(BaseModel): | ||
class BaseRTU(BaseModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make a base class for both RTU requests and responses to hold the newly respelled channel_prefix validator.
BaseRTURequest then becomes just a pass.
await rtu_client.wait_for_kernel_idle() | ||
|
||
queued_execution = await rtu_client.queue_execution('cell_1') | ||
queued_execution = await rtu_client.queue_execution("cell_1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new Black respelled the quote style here, sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah all of tests/ needs to have black applied post-double-quote-policy-change
Code looks good, tests look good. What do you have in mind for medium-term maintenance while testing out all downstream apps that use Origami, and whether they can support the pydantic 2.x bump? Do we leave this as an open PR and for regular updates to Origami we merge into main then update this PR? |
I think/suggest we can leave this PR as a PR while I work on at least the next concrete downstream useing branch, probablt in Origanist. Then produce a build of Origamist that uses this, and y'all could hoist up onto nightly or whatnot and get happy things work good, then go ahead and merge / make new releases from both. Then having new release of this clears the way (or one big step closer) to then being able to work on gate branch with upgraded pydantic. |
Upgrade pydantic to pydantic 2.4.2. Rewrite bits needing rewriting, with the assistance of the porting tool
bump-pydantic
.Wrote new unit tests for the validators that I had to respell.
Whole test suite passes w/o any deprecation warnings: