Skip to content

Commit

Permalink
Fix duration/memory config in config objects (#6827)
Browse files Browse the repository at this point in the history
  • Loading branch information
msullivan authored Feb 13, 2024
1 parent b688521 commit dbde513
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions edb/lib/_testmode.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ create extension package _conf VERSION '1.0' {
create required property extra -> int64 {
set readonly := true;
};
create required property duration_config: std::duration {
set default := <std::duration>'10 minutes';
};
};
create type ext::_conf::SecretObj extending ext::_conf::Obj {
create property secret -> std::str {
Expand Down
14 changes: 14 additions & 0 deletions edb/server/config/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
from . import spec


T_type = TypeVar('T_type', bound=type)


def _issubclass(
typ: type | statypes.CompositeTypeSpec, parent: T_type
) -> TypeGuard[T_type]:
return isinstance(typ, type) and issubclass(typ, parent)


class ConfigTypeSpec(statypes.CompositeTypeSpec):
def __call__(self, **kwargs) -> CompositeConfigType:
return CompositeConfigType(self, **kwargs)
Expand Down Expand Up @@ -177,6 +186,11 @@ def from_pyvalue(cls, data, *,

value = cls.from_pyvalue(value, tspec=actual_f_type, spec=spec)

elif _issubclass(f_type, statypes.Duration):
value = statypes.Duration.from_iso8601(value)
elif _issubclass(f_type, statypes.ConfigMemory):
value = statypes.ConfigMemory(value)

elif not isinstance(f_type, type) or not isinstance(value, f_type):
raise cls._err(
tspec,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_edgeql_ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16804,6 +16804,7 @@ async def _check(_cfg_obj='Config', **kwargs):
'name': '2', 'value': 'bar', 'opt_value': 'opt.'},
{'_tname': 'ext::_conf::SubObj',
'name': '3', 'value': 'baz', 'extra': 42,
'duration_config': 'PT10M',
'opt_value': None},
{'_tname': 'ext::_conf::SecretObj',
'name': '4', 'value': 'foo',
Expand Down Expand Up @@ -16849,6 +16850,7 @@ async def _check(_cfg_obj='Config', **kwargs):
value := 'quux',
};
CONFIGURE CURRENT DATABASE INSERT ext::_conf::SubObj {
duration_config := <std::duration>'PT10M',
extra := 42,
name := '3',
value := 'baz',
Expand Down

0 comments on commit dbde513

Please sign in to comment.