Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:
PGDATABASE: postgis
APP_HOST: 0.0.0.0
APP_PORT: 8080
ENABLED_EXTENSIONS: transaction,bulk_transactions,query,sort,fields,filter,pagination,collection_search

test-docs:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

- Disable transaction and bulk_transactions extensions by default **breaking change**

## [5.0.2] - 2025-04-07

### Fixed
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
- DB_MIN_CONN_SIZE=1
- DB_MAX_CONN_SIZE=1
- USE_API_HYDRATE=${USE_API_HYDRATE:-false}
- ENABLED_EXTENSIONS=transaction,bulk_transactions,query,sort,fields,filter,pagination,collection_search
ports:
- "8082:8082"
volumes:
Expand Down
34 changes: 20 additions & 14 deletions stac_fastapi/pgstac/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@

settings = Settings()

# application extensions
application_extensions_map = {
# transaction extensions
transaction_extensions_map = {
"transaction": TransactionExtension(
client=TransactionsClient(),
settings=settings,
Expand Down Expand Up @@ -93,25 +93,31 @@
"pagination": TokenPaginationExtension(),
}

known_extensions = {
*application_extensions_map.keys(),
enabled_extensions = {
*search_extensions_map.keys(),
*cs_extensions_map.keys(),
*itm_col_extensions_map.keys(),
"collection_search",
}

enabled_extensions = (
os.environ["ENABLED_EXTENSIONS"].split(",")
if "ENABLED_EXTENSIONS" in os.environ
else known_extensions
)
if ext := os.environ.get("ENABLED_EXTENSIONS"):
enabled_extensions = set(ext.split(","))

application_extensions = [
extension
for key, extension in application_extensions_map.items()
if key in enabled_extensions
]
application_extensions = []

if "transaction" in enabled_extensions:
application_extensions.append(
TransactionExtension(
client=TransactionsClient(),
settings=settings,
response_class=ORJSONResponse,
),
)

if "bulk_transactions" in enabled_extensions:
application_extensions.append(
BulkTransactionExtension(client=BulkTransactionsClient()),
)

# /search models
search_extensions = [
Expand Down
11 changes: 11 additions & 0 deletions tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@
)


async def test_default_app_no_transactions(
default_app_client, load_test_data, load_test_collection
):
coll = load_test_collection
item = load_test_data("test_item.json")
resp = await default_app_client.post(f"/collections/{coll['id']}/items", json=item)

# the default application does not have the transaction extensions enabled!
assert resp.status_code == 405


async def test_post_search_content_type(app_client):
params = {"limit": 1}
resp = await app_client.post("search", json=params)
Expand Down
43 changes: 43 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from stac_fastapi.extensions.third_party import BulkTransactionExtension
from stac_pydantic import Collection, Item

from stac_fastapi.pgstac.app import api as default_api
from stac_fastapi.pgstac.config import PostgresSettings, Settings
from stac_fastapi.pgstac.core import CoreCrudClient
from stac_fastapi.pgstac.db import close_db_connection, connect_to_db
Expand Down Expand Up @@ -334,3 +335,45 @@ async def app_client_no_ext(app_no_ext):
transport=ASGITransport(app=app_no_ext), base_url="http://test"
) as c:
yield c


@pytest.fixture(scope="function")
async def default_client_app():
api_settings = Settings(
testing=True,
)
api = default_api
api.settings = api_settings

return api


@pytest.fixture(scope="function")
async def default_app(default_client_app, database):
postgres_settings = PostgresSettings(
postgres_user=database.user,
postgres_pass=database.password,
postgres_host_reader=database.host,
postgres_host_writer=database.host,
postgres_port=database.port,
postgres_dbname=database.dbname,
)
logger.info("Creating app Fixture")
time.time()
app = default_client_app.app
await connect_to_db(app, postgres_settings=postgres_settings)

yield app

await close_db_connection(app)

logger.info("Closed Pools.")


@pytest.fixture(scope="function")
async def default_app_client(default_app):
logger.info("creating app_client")
async with AsyncClient(
transport=ASGITransport(app=default_app), base_url="http://test"
) as c:
yield c
Loading