Skip to content

Add warnings import for deprecated messages #668

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MakonnenMak
Copy link

@MakonnenMak MakonnenMak commented Jun 11, 2025

Summary

Issue reported here - #239

Fix Missing Warnings Import for Deprecated Protobuf Messages

Issue

When using deprecated protobuf messages or fields, betterproto generates code that calls warnings.warn() but was missing the required import warnings statement. This caused NameError: name 'warnings' is not defined when deprecated features were used.

Root Cause

The code generator properly added deprecation warnings but assumed the warnings module would be available without explicitly importing it.

Solution

  1. Modified the code generator to always include import warnings when deprecated features are detected
  2. Added test case (test_warnings_import_for_deprecated_message()) to verify:
    • Warnings module is properly imported in generated code
    • Works for both message-level and field-level deprecation

Testing

  • Added new test case that specifically verifies the import exists
  • Existing deprecation tests continue to pass
  • Manually verified deprecated messages/fields now work without NameError

Impact

Fixes runtime errors when using deprecated protobuf definitions while maintaining all existing warning behavior.

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
    • This change has an associated test.
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

@MakonnenMak MakonnenMak marked this pull request as draft June 11, 2025 04:21
@MakonnenMak MakonnenMak changed the title fix message deprecated Add warnings import for deprecated messages Jun 11, 2025
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