Skip to content

Commit 63cac39

Browse files
thomas-maschlervincentsaragojonhealy1
authored
update to pydantic 2 (#625)
* update to pydantic 2 * update changelog * typo * add CI for Python 3.12 * drop support for python 3.8 * update python version for docs * update python for docs docker container * update python version in dockerfile * handle post requests * test wrapper * pass through StacBaseModel * keep py38 * change install order * lint * revert back to >=3.8 in setup.py * add switch to use either TypeDict or StacPydantic Response * lint and format with ruff * remove comment * update change log * use Optional not | None * use Optional not | None * update dependencies * hard code versions and address other comments * remove response_model module, update openapi schema * add responses to transactions * do not wrap response into response_class * fix tests * update changelog, remove redundant variable * lint bench * reorder installs * do not push benchmark if not in stac-utils/stac-fastapi repo * Add text about response validation to readme. * fix warning * remove versions * fix * Update README.md * update changelog --------- Co-authored-by: vincentsarago <[email protected]> Co-authored-by: Jonathan Healy <[email protected]>
1 parent 1299bea commit 63cac39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+688
-417
lines changed

.github/workflows/cicd.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jobs:
8181
run: python -m pytest stac_fastapi/api/tests/benchmarks.py --benchmark-only --benchmark-columns 'min, max, mean, median' --benchmark-json output.json
8282

8383
- name: Store and benchmark result
84+
if: github.repository == 'stac-utils/stac-fastapi'
8485
uses: benchmark-action/github-action-benchmark@v1
8586
with:
8687
name: STAC FastAPI Benchmarks

.github/workflows/deploy_mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ jobs:
2020
- name: Checkout main
2121
uses: actions/checkout@v4
2222

23-
- name: Set up Python 3.8
23+
- name: Set up Python 3.11
2424
uses: actions/setup-python@v5
2525
with:
26-
python-version: 3.8
26+
python-version: 3.11
2727

2828
- name: Install dependencies
2929
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ docs/api/*
129129

130130
# Virtualenv
131131
venv
132+
.venv/
132133

133134
# IDE
134135
.vscode

.pre-commit-config.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
repos:
2-
- repo: https://github.com/charliermarsh/ruff-pre-commit
3-
rev: "v0.0.267"
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: "v0.2.2"
44
hooks:
55
- id: ruff
66
args: [--fix, --exit-non-zero-on-fix]
7-
- repo: https://github.com/psf/black
8-
rev: 23.3.0
9-
hooks:
10-
- id: black
7+
- id: ruff-format

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## [Unreleased]
44

5+
## Changes
6+
7+
* Update to pydantic v2 and stac_pydantic v3 ([#625](https://github.com/stac-utils/stac-fastapi/pull/625))
8+
* Removed internal Search and Operator Types in favor of stac_pydantic Types ([#625](https://github.com/stac-utils/stac-fastapi/pull/625))
9+
* Fix response model validation ([#625](https://github.com/stac-utils/stac-fastapi/pull/625))
10+
* Add Response Model to OpenAPI, even if model validation is turned off ([#625](https://github.com/stac-utils/stac-fastapi/pull/625))
11+
* Use status code 201 for Item/Collection creation ([#625](https://github.com/stac-utils/stac-fastapi/pull/625))
12+
* Replace Black with Ruff Format ([#625](https://github.com/stac-utils/stac-fastapi/pull/625))
13+
514
## [2.5.5.post1] - 2024-04-25
615

716
### Fixed
@@ -48,6 +57,7 @@
4857
* Add `/queryables` link to the landing page ([#587](https://github.com/stac-utils/stac-fastapi/pull/587))
4958
- `id`, `title`, `description` and `api_version` fields can be customized via env variables
5059
* Add `DeprecationWarning` for the `ContextExtension`
60+
* Add support for Python 3.12
5161

5262
### Changed
5363

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.8-slim as base
1+
FROM python:3.11-slim as base
22

33
# Any python libraries that require system libraries to be installed will likely
44
# need the following packages in order to build

Dockerfile.docs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.8-slim
1+
FROM python:3.11-slim
22

33
# build-essential is required to build a wheel for ciso8601
44
RUN apt update && apt install -y build-essential

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ Backends are hosted in their own repositories:
4141

4242
`stac-fastapi` was initially developed by [arturo-ai](https://github.com/arturo-ai).
4343

44+
45+
## Response Model Validation
46+
47+
A common question when using this package is how request and response types are validated?
48+
49+
This package uses [`stac-pydantic`](https://github.com/stac-utils/stac-pydantic) to validate and document STAC objects. However, by default, validation of response types is turned off and the API will simply forward responses without validating them against the Pydantic model first. This decision was made with the assumption that responses usually come from a (typed) database and can be considered safe. Extra validation would only increase latency, in particular for large payloads.
50+
51+
To turn on response validation, set `ENABLE_RESPONSE_MODELS` to `True`. Either as an environment variable or directly in the `ApiSettings`.
52+
53+
With the introduction of Pydantic 2, the extra [time it takes to validate models became negatable](https://github.com/stac-utils/stac-fastapi/pull/625#issuecomment-2045824578). While `ENABLE_RESPONSE_MODELS` still defaults to `False` there should be no penalty for users to turn on this feature but users discretion is advised.
54+
55+
4456
## Installation
4557

4658
```bash

pyproject.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
[tool.ruff]
2+
target-version = "py38" # minimum supported version
23
line-length = 90
4+
5+
[tool.ruff.lint]
36
select = [
47
"C9",
58
"D1",
@@ -9,13 +12,13 @@ select = [
912
"W",
1013
]
1114

12-
[tool.ruff.per-file-ignores]
15+
[tool.ruff.lint.per-file-ignores]
1316
"**/tests/**/*.py" = ["D1"]
1417

15-
[tool.ruff.isort]
18+
[tool.ruff.lint.isort]
1619
known-first-party = ["stac_fastapi"]
1720
known-third-party = ["stac_pydantic", "fastapi"]
1821
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
1922

20-
[tool.black]
21-
target-version = ["py38", "py39", "py310", "py311"]
23+
[tool.ruff.format]
24+
quote-style = "double"

stac_fastapi/api/setup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
desc = f.read()
77

88
install_requires = [
9-
"attrs",
10-
"pydantic[dotenv]<2",
11-
"stac_pydantic==2.0.*",
129
"brotli_asgi",
1310
"stac-fastapi.types",
1411
]

0 commit comments

Comments
 (0)