Skip to content

Commit

Permalink
Allow extra fields in the config
Browse files Browse the repository at this point in the history
Right now we cannot add extra fields to the config without it not being
backwards compatible.  Should follow the rules of protobuf here where
you can add new fields but they must be optional.
  • Loading branch information
joelynch committed Oct 4, 2023
1 parent d08f0dc commit c2080e2
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions astacus/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from contextlib import contextmanager
from multiprocessing.dummy import Pool # fastapi + fork = bad idea
from pathlib import Path
from fastapi.encoders import jsonable_encoder
from pydantic import BaseModel
from typing import Any, AsyncIterable, Callable, Dict, Final, Iterable, Optional, TypeVar, Union

Expand All @@ -39,12 +40,6 @@ class Config:
# enumname.value (it is also slightly less safe but oh well)
use_enum_values = True

# Extra values should be errors, as they are most likely typos
# which lead to grief when not detected. However, if we ever
# start deprecating some old fields and not wanting to parse
# them, this might need to be revisited.
extra = "forbid"

# Validate field default values too
validate_all = True

Expand All @@ -60,10 +55,8 @@ def jsondict(self, **kw):
# .dict() returns Python dict, but it has things that are not
# json serializable.
#
# We provide json seralizable dict (super inefficiently) here.
#
# This is mostly used for test code so that should be fine
return _json.loads(self.json(**kw))
# We provide json seralizable dict (super inefficiently).
return jsonable_encoder(self.dict(**kw))


def get_or_create_state(*, state: object, key: str, factory: Callable[[], Any]) -> Any:
Expand Down

0 comments on commit c2080e2

Please sign in to comment.