Fix startup with no categories; CI: suppress depreciation warning (very annoying with crypt!!)
Some checks failed
/ test (push) Failing after 31s

This commit is contained in:
phil 2024-12-15 20:35:17 +01:00
parent 98d67f0226
commit a5b2f07ff2
3 changed files with 29 additions and 21 deletions

View file

@ -34,4 +34,4 @@ jobs:
run: GISAF__DB__HOST=gisaf-database gisaf create-db
- name: Run tests (API call)
run: GISAF__DB__HOST=gisaf-database pytest -s tests/basic.py
run: GISAF__DB__HOST=gisaf-database pytest -s tests/basic.py -W ignore::DeprecationWarning

View file

@ -458,7 +458,10 @@ class ModelRegistry:
categories = await Category.get_df()
categories["title"] = categories.long_name.fillna(categories.description)
categories["store"] = categories.apply(get_store_name, axis=1)
if categories.empty:
categories["store"] = pd.Series(dtype=str)
else:
categories["store"] = categories.apply(get_store_name, axis=1)
categories["count"] = pd.Series(dtype=pd.Int64Dtype())
categories = categories.reset_index().set_index("store")
@ -483,7 +486,12 @@ class ModelRegistry:
## Set in the stores dataframe some useful properties, from the model class
## Maybe at some point it makes sense to get away from class-based definitions
if len(categories) > 0:
if categories.empty:
categories["store_name"] = None
categories["raw_model_store_name"] = None
categories["is_line_work"] = None
categories["raw_survey_model"] = None
else:
## XXX: redundant self.categories['store_name'] with self.categories['store']
# self.categories['store_name'] = self.categories.apply(
# lambda row: row.model.get_store_name(),
@ -496,11 +504,6 @@ class ModelRegistry:
categories["is_line_work"] = categories.apply(
lambda row: issubclass(row.model, LineWorkSurveyModel), axis=1
)
else:
categories["store_name"] = None
categories["raw_model_store_name"] = None
categories["is_line_work"] = None
categories["raw_survey_model"] = None
self.categories = categories
## --------------------
@ -523,7 +526,7 @@ class ModelRegistry:
self.custom_models["minor_group_1"] = None
self.custom_models["minor_group_2"] = None
if len(self.custom_models) > 0:
if not self.custom_models.empty:
(
self.custom_models["long_name"],
self.custom_models["custom_description"],
@ -539,7 +542,7 @@ class ModelRegistry:
self.custom_models["long_name"] + "-" + self.custom_models["db_schema"]
)
self.custom_models["title"] = self.custom_models["long_name"]
#self.custom_models.fillna(np.nan, inplace=True)
# self.custom_models.fillna(np.nan, inplace=True)
self.custom_models.replace([np.nan], [None], inplace=True)
## -------------------------
@ -551,7 +554,7 @@ class ModelRegistry:
self.custom_stores["group"] = "Community"
self.custom_stores["custom"] = True
self.custom_stores["is_db"] = False
if len(self.custom_stores) == 0:
if self.custom_stores.empty:
self.custom_stores["in_menu"] = False
else:
self.custom_stores["in_menu"] = self.custom_stores.apply(
@ -562,7 +565,7 @@ class ModelRegistry:
self.custom_stores["is_line_work"] = False
self.custom_stores["category"] = ""
if len(self.custom_stores) > 0:
if not self.custom_stores.empty:
(
self.custom_stores["long_name"],
self.custom_stores["description"],
@ -605,12 +608,18 @@ class ModelRegistry:
# self.stores['icon'],\
# self.stores['symbol'],\
(
self.stores["mapbox_type_default"],
self.stores["base_gis_type"],
self.stores["z_index"],
self.stores["attribution"],
) = zip(*self.stores.apply(fill_columns_from_model, axis=1))
if not self.stores.empty:
(
self.stores["mapbox_type_default"],
self.stores["base_gis_type"],
self.stores["z_index"],
self.stores["attribution"],
) = zip(*self.stores.apply(fill_columns_from_model, axis=1))
else:
self.stores["mapbox_type_default"] = pd.Series(dtype=str)
self.stores["base_gis_type"] = pd.Series(dtype=str)
self.stores["z_index"] = pd.Series(dtype=int)
self.stores["attribution"] = pd.Series(dtype=str)
self.stores["mapbox_type_custom"] = (
self.stores["mapbox_type_custom"].replace("", np.nan).fillna(np.nan)
@ -723,7 +732,7 @@ class ModelRegistry:
inplace=True,
)
df_live = pd.DataFrame.from_dict(self.geom_live_defs.values(), orient="columns")
if len(df_live) == 0:
if df_live.empty:
return
df_live.set_index("store", inplace=True)
## Adjust column names

View file

@ -19,7 +19,7 @@ from gisaf.models.authentication import User, UserRead
logger = logging.getLogger(__name__)
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
pwd_context = CryptContext(schemes=["sha256_crypt", "bcrypt"], deprecated="auto")
class Token(BaseModel):
@ -165,4 +165,3 @@ def create_access_token(data: dict, expires_delta: timedelta):
to_encode, conf.crypto.secret, algorithm=conf.crypto.algorithm
)
return encoded_jwt