From 0ad4b14d89702c028f4e23395a33c0c26c6b18f4 Mon Sep 17 00:00:00 2001 From: Matt Diez Date: Tue, 27 Aug 2024 12:57:29 -0500 Subject: [PATCH 1/7] Added in environment variable for sorting/config --- docs/src/user_guide/configuration.md | 1 + tipg/collections.py | 6 +++++- tipg/settings.py | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/src/user_guide/configuration.md b/docs/src/user_guide/configuration.md index 6290966..e4bf326 100644 --- a/docs/src/user_guide/configuration.md +++ b/docs/src/user_guide/configuration.md @@ -129,6 +129,7 @@ prefix: **`TIPG_`** - **DEFAULT_FEATURES_LIMIT** (int): Set the default `Limit` values for `/items` endpoint. Default is `10` - **MAX_FEATURES_PER_QUERY** (int): Set the maximum number of features the `/items` endpoint can return. Default is `10000`. +- **SORT_COLUMNS** (bool): Sort the `columns` for a feature alphabetically. Default is `True`. ```bash TIPG_DEFAULT_FEATURES_LIMIT=1000 TIPG_MAX_FEATURES_PER_QUERY=2000 diff --git a/tipg/collections.py b/tipg/collections.py index d50afa4..09e313e 100644 --- a/tipg/collections.py +++ b/tipg/collections.py @@ -951,7 +951,11 @@ async def get_collection_index( # noqa: C901 table_conf = table_confs.get(confid, TableConfig()) # Make sure that any properties set in conf exist in table - columns = sorted(table.get("properties", []), key=lambda d: d["name"]) + if features_settings.sort_columns: + columns = sorted(table.get("properties", []), key=lambda d: d["name"]) + else: + columns = table.get("properties", []) + properties_setting = table_conf.properties or [c["name"] for c in columns] # ID Column diff --git a/tipg/settings.py b/tipg/settings.py index b050136..20058ac 100644 --- a/tipg/settings.py +++ b/tipg/settings.py @@ -86,6 +86,7 @@ class FeaturesSettings(BaseSettings): default_features_limit: int = Field(10, ge=0) max_features_per_query: int = Field(10000, ge=0) + sort_columns: bool = True model_config = {"env_prefix": "TIPG_", "env_file": ".env", "extra": "ignore"} From a7dbc205b2b21c0009632c8f5864f760a0e214b2 Mon Sep 17 00:00:00 2001 From: Matt Diez Date: Thu, 29 Aug 2024 10:00:25 -0500 Subject: [PATCH 2/7] Fixing whitespace --- tipg/collections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tipg/collections.py b/tipg/collections.py index 09e313e..3e0a1eb 100644 --- a/tipg/collections.py +++ b/tipg/collections.py @@ -955,7 +955,7 @@ async def get_collection_index( # noqa: C901 columns = sorted(table.get("properties", []), key=lambda d: d["name"]) else: columns = table.get("properties", []) - + properties_setting = table_conf.properties or [c["name"] for c in columns] # ID Column From c22ea2f1b227085635a6b1641276c650479f2604 Mon Sep 17 00:00:00 2001 From: Matt Diez <92321272+mattdiez-at@users.noreply.github.com> Date: Thu, 29 Aug 2024 11:21:06 -0500 Subject: [PATCH 3/7] Switched to simpler branching structure Co-authored-by: Vincent Sarago --- tipg/collections.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tipg/collections.py b/tipg/collections.py index 3e0a1eb..e6529fc 100644 --- a/tipg/collections.py +++ b/tipg/collections.py @@ -951,10 +951,9 @@ async def get_collection_index( # noqa: C901 table_conf = table_confs.get(confid, TableConfig()) # Make sure that any properties set in conf exist in table + columns = table.get("properties", []) if features_settings.sort_columns: - columns = sorted(table.get("properties", []), key=lambda d: d["name"]) - else: - columns = table.get("properties", []) + columns = sorted(columns, key=lambda d: d["name"]) properties_setting = table_conf.properties or [c["name"] for c in columns] From a968b7298d7c1454747270062f97d3d20ab9a649 Mon Sep 17 00:00:00 2001 From: Matt Diez Date: Thu, 29 Aug 2024 16:09:29 -0500 Subject: [PATCH 4/7] Switched to --- docs/src/user_guide/configuration.md | 2 +- tipg/collections.py | 2 +- tipg/settings.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/user_guide/configuration.md b/docs/src/user_guide/configuration.md index e4bf326..b23e66f 100644 --- a/docs/src/user_guide/configuration.md +++ b/docs/src/user_guide/configuration.md @@ -84,6 +84,7 @@ prefix: **`TIPG_`** - **TABLE_CONFIG_ _ {schemaId}_{tableId} _ _DATETIMECOL** (str): Table's datetime column name - **TABLE_CONFIG_ _ {schemaId}_{tableId} _ _PK** (str): Table's primary key - **TABLE_CONFIG_ _ {schemaId}_{tableId} _ _PROPERTIES** (list of string): Select specific properties from table (for filtering and output) +- **SORT_COLUMNS** (bool): Sort the `columns` for a table alphabetically. Default is `True`. ```bash TIPG_TABLE_CONFIG__pgstac_items__PK=id @@ -129,7 +130,6 @@ prefix: **`TIPG_`** - **DEFAULT_FEATURES_LIMIT** (int): Set the default `Limit` values for `/items` endpoint. Default is `10` - **MAX_FEATURES_PER_QUERY** (int): Set the maximum number of features the `/items` endpoint can return. Default is `10000`. -- **SORT_COLUMNS** (bool): Sort the `columns` for a feature alphabetically. Default is `True`. ```bash TIPG_DEFAULT_FEATURES_LIMIT=1000 TIPG_MAX_FEATURES_PER_QUERY=2000 diff --git a/tipg/collections.py b/tipg/collections.py index e6529fc..b003f77 100644 --- a/tipg/collections.py +++ b/tipg/collections.py @@ -952,7 +952,7 @@ async def get_collection_index( # noqa: C901 # Make sure that any properties set in conf exist in table columns = table.get("properties", []) - if features_settings.sort_columns: + if table_settings.sort_columns: columns = sorted(columns, key=lambda d: d["name"]) properties_setting = table_conf.properties or [c["name"] for c in columns] diff --git a/tipg/settings.py b/tipg/settings.py index 20058ac..d14933a 100644 --- a/tipg/settings.py +++ b/tipg/settings.py @@ -62,7 +62,8 @@ class TableSettings(BaseSettings): fallback_key_names: List[str] = ["ogc_fid", "id", "pkey", "gid"] table_config: Dict[str, TableConfig] = {} - + sort_columns: bool = True + model_config = { "env_prefix": "TIPG_", "env_file": ".env", @@ -86,7 +87,6 @@ class FeaturesSettings(BaseSettings): default_features_limit: int = Field(10, ge=0) max_features_per_query: int = Field(10000, ge=0) - sort_columns: bool = True model_config = {"env_prefix": "TIPG_", "env_file": ".env", "extra": "ignore"} From 4632aa898cde13151405d6ccdddd418d738f73b1 Mon Sep 17 00:00:00 2001 From: Matt Diez Date: Thu, 29 Aug 2024 16:10:46 -0500 Subject: [PATCH 5/7] changed order --- docs/src/user_guide/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/user_guide/configuration.md b/docs/src/user_guide/configuration.md index b23e66f..fa43ce6 100644 --- a/docs/src/user_guide/configuration.md +++ b/docs/src/user_guide/configuration.md @@ -79,12 +79,12 @@ prefix: **`TIPG_`** - **DATETIME_EXTENT** (bool): Fetch datetime extent by going throught all rows. Default is `True` - **FALLBACK_KEY_NAMES** (list of string): Primary Key names to look for in the tables. Default is `["ogc_fid", "id", "pkey", "gid"]` +- **SORT_COLUMNS** (bool): Sort the `columns` for a table alphabetically. Default is `True`. - **TABLE_CONFIG** (dict of `TableConfig`) - **TABLE_CONFIG_ _ {schemaId}_{tableId} _ _GEOMCOL** (str): Table's geometry/geography column name - **TABLE_CONFIG_ _ {schemaId}_{tableId} _ _DATETIMECOL** (str): Table's datetime column name - **TABLE_CONFIG_ _ {schemaId}_{tableId} _ _PK** (str): Table's primary key - **TABLE_CONFIG_ _ {schemaId}_{tableId} _ _PROPERTIES** (list of string): Select specific properties from table (for filtering and output) -- **SORT_COLUMNS** (bool): Sort the `columns` for a table alphabetically. Default is `True`. ```bash TIPG_TABLE_CONFIG__pgstac_items__PK=id From 2324fb625c021d82619f87c879f326cd72462ea6 Mon Sep 17 00:00:00 2001 From: Matt Diez Date: Fri, 30 Aug 2024 07:58:32 -0500 Subject: [PATCH 6/7] Re-ran black. Removed whitespace --- tipg/settings.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tipg/settings.py b/tipg/settings.py index d14933a..98bc99a 100644 --- a/tipg/settings.py +++ b/tipg/settings.py @@ -63,7 +63,7 @@ class TableSettings(BaseSettings): fallback_key_names: List[str] = ["ogc_fid", "id", "pkey", "gid"] table_config: Dict[str, TableConfig] = {} sort_columns: bool = True - + model_config = { "env_prefix": "TIPG_", "env_file": ".env", @@ -143,9 +143,7 @@ class PostgresSettings(BaseSettings): # https://github.com/tiangolo/full-stack-fastapi-postgresql/blob/master/%7B%7Bcookiecutter.project_slug%7D%7D/backend/app/app/core/config.py#L42 @field_validator("database_url", mode="before") - def assemble_db_connection( - cls, v: Optional[str], info: ValidationInfo - ) -> PostgresDsn: + def assemble_db_connection(cls, v: Optional[str], info: ValidationInfo) -> PostgresDsn: """Validate db url settings.""" if isinstance(v, str): return PostgresDsn(v) From 6b7ebcce083c48bb9a91fdac9ad95ed3ce1eb52d Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Fri, 30 Aug 2024 16:02:34 +0200 Subject: [PATCH 7/7] update changelog --- CHANGES.md | 6 +++++- tipg/settings.py | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f232fae..4fe0aef 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). Note: Minor version `0.X.0` update might break the API, It's recommended to pin `tipg` to minor version: `tipg>=0.1,<0.2` +## Unreleased + +* add `TIPG_SORT_COLUMNS` settings to enable/disable columns sorting (default to `True`) (author @mattdiez-at, https://github.com/developmentseed/tipg/pull/187) + ## [0.7.2] - 2024-08-27 * move back to `fastapi` dependency @@ -310,7 +314,7 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin - Initial release [unreleased]: https://github.com/developmentseed/tipg/compare/0.7.2...HEAD -[0.7.1]: https://github.com/developmentseed/tipg/compare/0.7.1...0.7.2 +[0.7.2]: https://github.com/developmentseed/tipg/compare/0.7.1...0.7.2 [0.7.1]: https://github.com/developmentseed/tipg/compare/0.7.0...0.7.1 [0.7.0]: https://github.com/developmentseed/tipg/compare/0.6.3...0.7.0 [0.6.3]: https://github.com/developmentseed/tipg/compare/0.6.2...0.6.3 diff --git a/tipg/settings.py b/tipg/settings.py index 98bc99a..f57855b 100644 --- a/tipg/settings.py +++ b/tipg/settings.py @@ -143,7 +143,9 @@ class PostgresSettings(BaseSettings): # https://github.com/tiangolo/full-stack-fastapi-postgresql/blob/master/%7B%7Bcookiecutter.project_slug%7D%7D/backend/app/app/core/config.py#L42 @field_validator("database_url", mode="before") - def assemble_db_connection(cls, v: Optional[str], info: ValidationInfo) -> PostgresDsn: + def assemble_db_connection( + cls, v: Optional[str], info: ValidationInfo + ) -> PostgresDsn: """Validate db url settings.""" if isinstance(v, str): return PostgresDsn(v)