Skip to content

Commit c8840bf

Browse files
Fix config export command and remove optionals from its output (#234)
* Fix `config export` command and remove optionals from its output * Cleanup * Fix changelog
1 parent 96caeb0 commit c8840bf

File tree

6 files changed

+57
-29
lines changed

6 files changed

+57
-29
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Please use [this](https://docs.gitlab.com/ee/development/changelog.html) documen
77
### Fixed
88

99
* ci: Removed `black 21.12b0` dependency since bug in `datamodel-codegen-generator` is fixed.
10-
* config: Verify `advanced.scheduler` config for correctness unsupported features.
10+
* cli: Fixed `config export` command crash when `advanced.reindex` dictionary is present.
11+
* cli: Removed optionals from `config export` output so the result can be loaded again.
12+
* config: Verify `advanced.scheduler` config for the correctness and unsupported features.
1113
* context: Fixed ignored `wait` argument of `fire_hook` method.
1214
* hasura: Fixed processing relation fields with missing `related_name`.
1315
* jobs: Fixed default `apscheduler` config.

poetry.lock

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dipdup/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from dipdup.enums import SkipHistory
5050
from dipdup.exceptions import ConfigInitializationException
5151
from dipdup.exceptions import ConfigurationError
52+
from dipdup.utils import exclude_none
5253
from dipdup.utils import import_from
5354
from dipdup.utils import pascal_to_snake
5455
from dipdup.utils import snake_to_pascal
@@ -1072,10 +1073,12 @@ def load(
10721073

10731074
def dump(self) -> str:
10741075
config_json = json.dumps(self, default=pydantic_encoder)
1076+
config_yaml = yaml.safe_load(config_json)
1077+
10751078
return cast(
10761079
str,
10771080
yaml.dump(
1078-
yaml.safe_load(config_json),
1081+
exclude_none(config_yaml),
10791082
indent=2,
10801083
default_flow_style=False,
10811084
),

src/dipdup/enums.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ class IndexStatus(Enum):
3535
SYNCING = 'SYNCING'
3636
REALTIME = 'REALTIME'
3737
ROLLBACK = 'ROLLBACK'
38+
# TODO: Drop in 5.0.0
3839
ONESHOT = 'ONESHOT'
3940

4041

42+
# TODO: Drop in 5.0.0
4143
class ReindexingReason(ReversedEnum):
4244
MANUAL = 'triggered manually from callback'
4345
MIGRATION = 'applied migration requires reindexing'
@@ -48,7 +50,8 @@ class ReindexingReason(ReversedEnum):
4850
MISSING_INDEX_TEMPLATE = 'index template is missing, can\'t restore index state'
4951

5052

51-
class ReindexingReasonC(Enum):
53+
# NOTE: Used as a key in config, must inherit from str
54+
class ReindexingReasonC(str, Enum):
5255
manual = 'manual'
5356
migration = 'migration'
5457
rollback = 'rollback'

src/dipdup/utils/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,11 @@ def skip_ci(fn):
177177
if os.environ.get('CI'):
178178
return skip('CI environment, skipping')(fn)
179179
return fn
180+
181+
182+
def exclude_none(config_json):
183+
if isinstance(config_json, (list, tuple)):
184+
return [exclude_none(i) for i in config_json if i is not None]
185+
if isinstance(config_json, dict):
186+
return {k: exclude_none(v) for k, v in config_json.items() if v is not None}
187+
return config_json

tests/test_dipdup/test_config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import tempfile
12
from os.path import dirname
23
from os.path import join
34
from typing import Callable
@@ -34,3 +35,14 @@ async def test_validators(self):
3435
ContractConfig(address='lalalalalalalalalalalalalalalalalala')
3536
with self.assertRaises(ConfigurationError):
3637
TzktDatasourceConfig(kind='tzkt', url='not_an_url')
38+
39+
async def test_dump(self):
40+
config = DipDupConfig.load([self.path])
41+
config.initialize()
42+
43+
tmp = tempfile.mkstemp()[1]
44+
with open(tmp, 'w') as f:
45+
f.write(config.dump())
46+
47+
config = DipDupConfig.load([tmp], environment=False)
48+
config.initialize()

0 commit comments

Comments
 (0)