Skip to content

Fixes #282: fix Pydantic v2 compatibility (prevent plugin startup crash due to BaseSettings import)#285

Open
DaniloVerde wants to merge 1 commit intostac-utils:mainfrom
DaniloVerde:fix-issue-282
Open

Fixes #282: fix Pydantic v2 compatibility (prevent plugin startup crash due to BaseSettings import)#285
DaniloVerde wants to merge 1 commit intostac-utils:mainfrom
DaniloVerde:fix-issue-282

Conversation

@DaniloVerde
Copy link
Copy Markdown

Summary

This PR fixes a startup crash in the qgis_stac plugin on QGIS LTR / Python 3.12 environments where Pydantic 2.x is installed.

Problem

When QGIS loads the plugin, classFactory fails with the following error:

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

Root Cause

In lib/planetary_computer/settings.py, the Settings class inherited from pydantic.BaseSettings.
In Pydantic 2.x, BaseSettings is no longer available from that import path.

Changes

  • Added a version-tolerant import chain for BaseSettings:
    • from pydantic_settings import BaseSettings
    • fallback: from pydantic.v1 import BaseSettings
    • fallback: from pydantic import BaseSettings
  • Updated the Settings class declaration to inherit from the resolved BaseSettings symbol.

Why This Approach

  • Works on Pydantic 2.x without requiring immediate environment changes.
  • Preserves compatibility with Pydantic 1.x and legacy setups.
  • Keeps the change surface minimal (single file).

Testing and Validation

  • Static check: no errors reported in the modified file.
  • Runtime smoke test: loading the settings module and calling Settings.get() succeeds in local workspace validation.
  • Manual verification in QGIS:
    1. Restart QGIS.
    2. Enable or reload the qgis_stac plugin.
    3. Confirm that the plugin loads without the classFactory/BaseSettings error.
  • Tested on QGIS 3.44.8 - Solothurn

Impact

  • Fixes plugin startup failure.
  • No intended behavior change in settings handling (env file, env prefix, default values).

Notes

This is a targeted compatibility fix and does not change the plugin public API.

References

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