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

Port to pydantic 2 #192

Merged
merged 24 commits into from
Nov 6, 2023
Merged

Port to pydantic 2 #192

merged 24 commits into from
Nov 6, 2023

Conversation

jlrobins
Copy link
Contributor

@jlrobins jlrobins commented Oct 19, 2023

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:

pytest tests
================================================================================ test session starts ================================================================================
platform darwin -- Python 3.11.6, pytest-7.4.2, pluggy-1.3.0
rootdir: /Users/jlrobins/noteable/origami
configfile: pyproject.toml
plugins: anyio-4.0.0, asyncio-0.19.0, cov-4.1.0
asyncio: mode=Mode.AUTO
collected 32 items                                                                                                                                                                  

tests/e2e/api/test_files.py ..                                                                                                                                                [  6%]
tests/e2e/api/test_projects.py ..                                                                                                                                             [ 12%]
tests/e2e/api/test_spaces.py ..                                                                                                                                               [ 18%]
tests/e2e/api/test_users.py .                                                                                                                                                 [ 21%]
tests/e2e/rtu/test_execution.py ...                                                                                                                                           [ 31%]
tests/e2e/rtu/test_notebook.py .....                                                                                                                                          [ 46%]
tests/unit/test_sql_cells.py ..                                                                                                                                               [ 53%]
tests/unit/test_version.py .                                                                                                                                                  [ 56%]
tests/unit/models/test_files.py .                                                                                                                                             [ 59%]
tests/unit/models/test_notebook.py ....                                                                                                                                       [ 71%]
tests/unit/models/test_project.py .                                                                                                                                           [ 75%]
tests/unit/models/test_rtu_base.py ......                                                                                                                                     [ 93%]
tests/unit/models/test_space.py .                                                                                                                                             [ 96%]
tests/unit/models/test_user.py .                                                                                                                                              [100%]

================================================================================ 32 passed in 43.14s ================================================================================

@jlrobins jlrobins marked this pull request as ready for review October 23, 2023 14:26
@@ -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:
Copy link
Contributor Author

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.

# 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"
Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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):
Copy link
Contributor Author

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")
Copy link
Contributor Author

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.

Copy link
Contributor

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

@jlrobins jlrobins requested review from kafonek and shouples and removed request for kafonek October 23, 2023 14:35
@jlrobins jlrobins requested a review from kafonek October 23, 2023 14:36
@kafonek
Copy link
Contributor

kafonek commented Oct 23, 2023

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?

@jlrobins
Copy link
Contributor Author

jlrobins commented Oct 23, 2023

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.

@kafonek kafonek merged commit 583d25c into main Nov 6, 2023
6 checks passed
@kafonek kafonek deleted the upgrade_pydantic branch November 6, 2023 19:59
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.

2 participants