Skip to content

Conversation

salah9003
Copy link

Summary

Fixes Pydantic v2.11+ compatibility issue where google-genai v1.30.0 fails to import due to deprecated populate_by_name configuration parameter.

Problem

Import fails with pydantic_core._pydantic_core.SchemaError: Invalid Schema: model.config.populate_by_name Extra inputs are not permitted when using Pydantic v2.11+.

Root Cause

google/genai/_common.py line 417 uses deprecated populate_by_name=True parameter. According to Pydantic documentation: "populate_by_name usage is not recommended in v2.11+ and will be deprecated in v3." The official replacement is validate_by_name=True + validate_by_alias=True.

Solution

  • Add version detection for Pydantic v1 vs v2
  • Use validate_by_name=True + validate_by_alias=True for Pydantic v2.11+
  • Keep populate_by_name=True for Pydantic v1 backward compatibility
  • Maintains identical functionality across versions

Testing

  • Tested with Pydantic v2.11.7: import successful, no errors
  • BaseModel instantiation and functionality verified
  • Backward compatible with Pydantic v1

Impact

Resolves breaking change that forced users to downgrade to google-genai v1.29.0 when using modern Pydantic versions.

References

Copy link

google-cla bot commented Aug 17, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@salah9003 salah9003 force-pushed the fix-pydantic-v2-compatibility branch from 4093448 to 097a6c5 Compare August 17, 2025 14:17
Replace deprecated populate_by_name with validate_by_name/validate_by_alias
Add version detection for backward compatibility with Pydantic v1
Fixes SchemaError when importing google.genai with Pydantic v2.11+
@salah9003 salah9003 force-pushed the fix-pydantic-v2-compatibility branch from 190f66e to 0e5a276 Compare August 25, 2025 21:04
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