pygeoapi icon indicating copy to clipboard operation
pygeoapi copied to clipboard

Compatibility with Pydantic >= 2 through pydantic.v1

Open SarahG-579462 opened this issue 1 year ago • 2 comments

Overview

Recently, pygeoapi's pydantic was downgraded from 2.0-compatible to pydantic < 1. This removed compatibility with two of our libraries, xscen and xclim, for climate data processing, due to intake-esm's current requirement on pydantic > 2

Because we require these in the use of our pygeoapi process plugins, this change forced us to use either very outdated versions of xscen (and thus xarray, pandas, xclim, etc.), or a very outdated version of pygeoapi.

Thankfully, a simple fix is available by the use of pydantic 2's backwards-compatible pydantic.v1 module.

It is not entirely clear to me why pydantic was downgraded, the best explanation I can see in the discussion was due to "versionitis". I was, however, able to run all tests with the latest version of pydantic installed in this fashion. The way this PR is written, if pydantic >= 2 is not available on the operating system in question, everything will continue as-is.

Related Issue / discussion

Pydantic issues: #1573 #1341 #1584

Additional information

Dependency policy (RFC2)

  • [x] I have ensured that this PR meets RFC2 requirements

(It follows RFC2 as far as I understand, as it allows backwards compatibility with pydantic < 2)

Updates to public demo

  • [ ] I have ensured that breaking changes to the pygeoapi master demo server have been addressed
    • [ ] https://github.com/geopython/demo.pygeoapi.io/blob/master/services/pygeoapi_master/local.config.yml

No breaking changes shuold ensue as a result of this PR, since it is backwards compatible. I am not entirely sure how to test this demo server, help would be appreciated here.

Contributions and licensing

(as per https://github.com/geopython/pygeoapi/blob/master/CONTRIBUTING.md#contributions-and-licensing)

  • [x] I'd like to contribute [feature X|bugfix Y|docs|something else] to pygeoapi. I confirm that my contributions to pygeoapi will be compatible with the pygeoapi license guidelines at the time of contribution
  • [x] I have already previously agreed to the pygeoapi Contributions and Licensing Guidelines

SarahG-579462 avatar May 17 '24 18:05 SarahG-579462

Note: I had to change one of the github actions, since docker images do not allow capital letters, and the repository for our organisation is "Ouranosinc". Feel free to discard this change, if needed.

SarahG-579462 avatar May 17 '24 18:05 SarahG-579462

To add, it would be valuable to have pygeoapi.models.pydantic that covers the try/except in one place and have the rest of code import from pygeoapi.models.pydantic

tomkralidis avatar May 30 '24 23:05 tomkralidis

Closing given https://github.com/geopython/pygeoapi/issues/1664#issuecomment-2192417748

tomkralidis avatar Jul 21 '24 15:07 tomkralidis