Skip to content

Added pydanticV2 support. #11

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

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
689 changes: 392 additions & 297 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ keywords = ["taskiq", "pipelines", "tasks", "distributed", "async"]
python = "^3.8.1"
taskiq = ">=0.0.8, <1"
typing-extensions = "^4.3.0"
pydantic = "^1.6.2"
pydantic = "^2"

[tool.poetry.dev-dependencies]
pytest = "^7"
Expand Down
6 changes: 4 additions & 2 deletions taskiq_pipelines/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ async def post_save( # noqa: C901, WPS212
return
pipeline_data = message.labels[PIPELINE_DATA]
try:
steps_data = pydantic.parse_raw_as(List[DumpedStep], pipeline_data)
steps_data = pydantic.TypeAdapter(List[DumpedStep]).validate_json(
pipeline_data,
)
except ValueError:
return
if current_step_num + 1 >= len(steps_data):
Expand Down Expand Up @@ -99,7 +101,7 @@ async def on_error(
return
pipe_data = message.labels[PIPELINE_DATA]
try:
steps = pydantic.parse_raw_as(List[DumpedStep], pipe_data)
steps = pydantic.TypeAdapter(List[DumpedStep]).validate_json(pipe_data)
except ValueError:
return
if current_step_num == len(steps) - 1:
Expand Down
4 changes: 2 additions & 2 deletions taskiq_pipelines/pipeliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def dumps(self) -> str:
:returns: serialized pipeline.
"""
return json.dumps(
[step.dict() for step in self.steps],
[step.model_dump() for step in self.steps],
)

@classmethod
Expand All @@ -344,7 +344,7 @@ def loads(cls, broker: AsyncBroker, pipe_data: str) -> "Pipeline[Any, Any]":
:return: new
"""
pipe: "Pipeline[Any, Any]" = Pipeline(broker)
pipe.steps = pydantic.parse_raw_as(List[DumpedStep], pipe_data)
pipe.steps = pydantic.TypeAdapter(List[DumpedStep]).validate_json(pipe_data)
return pipe

async def kiq(
Expand Down
4 changes: 2 additions & 2 deletions taskiq_pipelines/steps/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def dumps(self) -> str:

:return: returns json.
"""
return self.json()
return self.model_dump_json()

@classmethod
def loads(cls, data: str) -> "FilterStep":
Expand All @@ -94,7 +94,7 @@ def loads(cls, data: str) -> "FilterStep":
:param data: dumped data.
:return: parsed step.
"""
return pydantic.parse_raw_as(FilterStep, data)
return pydantic.TypeAdapter(FilterStep).validate_json(data)

async def act(
self,
Expand Down
4 changes: 2 additions & 2 deletions taskiq_pipelines/steps/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def dumps(self) -> str:

:return: returns json.
"""
return self.json()
return self.model_dump_json()

@classmethod
def loads(cls, data: str) -> "MapperStep":
Expand All @@ -91,7 +91,7 @@ def loads(cls, data: str) -> "MapperStep":
:param data: dumped data.
:return: parsed step.
"""
return pydantic.parse_raw_as(MapperStep, data)
return pydantic.TypeAdapter(MapperStep).validate_json(data)

async def act(
self,
Expand Down
4 changes: 2 additions & 2 deletions taskiq_pipelines/steps/sequential.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def dumps(self) -> str:

:return: returns json.
"""
return self.json()
return self.model_dump_json()

@classmethod
def loads(cls, data: str) -> "SequentialStep":
Expand All @@ -56,7 +56,7 @@ def loads(cls, data: str) -> "SequentialStep":
:param data: dumped data.
:return: parsed step.
"""
return pydantic.parse_raw_as(SequentialStep, data)
return pydantic.TypeAdapter(SequentialStep).validate_json(data)

async def act(
self,
Expand Down