Skip to content

fix: avoid Pydantic namespace shadowing in Message.parse - #254

Open
AndersonBY wants to merge 1 commit into
betterproto:mainfrom
AndersonBY:fix/pydantic-parse-namespace-shadow-lib091
Open

fix: avoid Pydantic namespace shadowing in Message.parse#254
AndersonBY wants to merge 1 commit into
betterproto:mainfrom
AndersonBY:fix/pydantic-parse-namespace-shadow-lib091

Conversation

@AndersonBY

Copy link
Copy Markdown

Generated Pydantic dataclasses can use a module-level data alias for nested enums. Message.parse(data) currently keeps its bytes parameter in the local frame while constructing the dataclass; Pydantic lazy forward-reference resolution can then resolve data.SomeEnum against bytes and fail on a legal payload.

This patch deletes the parameter after creating the BytesIO stream, before constructing the message. It preserves positional and keyword call compatibility and adds regression coverage for both forms using the generated-module shape.

Validated on Python 3.12 with the 0.9.1 library source and Pydantic 2.13.x.

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.

1 participant