Skip to content

Fix BaseSettings import for pydantic v2 (use pydantic.v1 fallback)#281

Open
yugo-kato wants to merge 1 commit intostac-utils:mainfrom
yugo-kato:fix/pydantic-basesettings
Open

Fix BaseSettings import for pydantic v2 (use pydantic.v1 fallback)#281
yugo-kato wants to merge 1 commit intostac-utils:mainfrom
yugo-kato:fix/pydantic-basesettings

Conversation

@yugo-kato
Copy link

This PR restores compatibility with Pydantic v2 for the bundled planetary_computer settings module by using a small import shim for BaseSettings.

QGIS environments can end up with pydantic>=2, where BaseSettings was moved out of pydantic (to pydantic-settings). This can prevent the plugin from loading with:

pydantic.errors.PydanticImportError: BaseSettings has been moved to the pydantic-settings package

Related: #261

What changed

  • Import BaseSettings from pydantic.v1 when available (Pydantic v2), otherwise fall back to pydantic (Pydantic v1).
  • Update Settings to inherit from the imported BaseSettings instead of pydantic.BaseSettings.

This keeps the plugin working across both Pydantic v1 and v2 without forcing users to install additional packages in constrained QGIS Python setups.

Why this approach

  • Pydantic v2 provides a compatibility namespace pydantic.v1, which allows v1-style BaseSettings usage.
  • Avoids introducing/depending on pydantic-settings in environments where adding Python dependencies is difficult (common for QGIS plugin users).

How to reproduce (before)

  1. Use a QGIS Python environment where pydantic>=2 is present.
  2. Install/enable the plugin.
  3. Plugin fails to load due to PydanticImportError complaining about BaseSettings.

Note: This change was drafted with assistance from ChatGPT Codex and reviewed/validated by the author.

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