Skip to content

Commit 5a9122a

Browse files
committed
style: run linting and static typing
1 parent 7dc4e63 commit 5a9122a

4 files changed

Lines changed: 61 additions & 48 deletions

File tree

src/dve/core_engine/backends/base/rules.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@
4545
TableUnion,
4646
)
4747
from dve.core_engine.backends.types import Entities, EntityType, StageSuccessful
48-
from dve.core_engine.configuration.v1.hierarchy import (
49-
EntityHierarchy,
50-
HierarchyNode,
51-
)
48+
from dve.core_engine.configuration.v1.hierarchy import EntityHierarchy, HierarchyNode
5249
from dve.core_engine.constants import ORPHANED_RECORD_ENTITY_NAME
5350
from dve.core_engine.exceptions import CriticalProcessingError
5451
from dve.core_engine.loggers import get_logger
@@ -418,7 +415,9 @@ def process_node(
418415
)
419416

420417
if no_orphs > 0:
421-
self.logger.info(f"Removing records with missing parent from {current_entity_name}")
418+
self.logger.info(
419+
f"Removing records with missing parent from {current_entity_name}"
420+
)
422421
location = list(node.join_fields.values())[0]
423422
with BackgroundMessageWriter(
424423
working_directory=working_directory,
@@ -435,23 +434,26 @@ def process_node(
435434
code=node.missing_parent_id_error_code,
436435
message=node.missing_parent_id_error_message,
437436
location=location,
437+
),
438+
),
439+
)
440+
# moved to batch the write - risky if large number of
441+
msg_writer.write_queue.put(
442+
[
443+
FeedbackMessage(
444+
entity=current_entity_name,
445+
record=record, # type: ignore
446+
error_location=location,
447+
error_message=node.missing_parent_id_error_message,
448+
failure_type="record",
449+
error_type="record",
450+
error_code=node.missing_parent_id_error_code,
451+
reporting_field=location,
452+
category="Parent Missing",
438453
)
439-
)
454+
for record in _orph_records
455+
]
440456
)
441-
# moved to batch the write - risky if large number of
442-
msg_writer.write_queue.put([
443-
FeedbackMessage(
444-
entity=current_entity_name,
445-
record=record, # type: ignore
446-
error_location=location,
447-
error_message=node.missing_parent_id_error_message,
448-
failure_type="record",
449-
error_type="record",
450-
error_code=node.missing_parent_id_error_code,
451-
reporting_field=location,
452-
category="Parent Missing",
453-
)
454-
for record in _orph_records ])
455457

456458
if node.children:
457459
for child_node in node.children:

src/dve/core_engine/backends/metadata/rules.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ class OrphanIdentification(AbstractConditionalJoin):
553553
554554
"""
555555

556+
556557
Step = Union[AbstractStep, Literal["sync"]]
557558
"""A step within a rule. This is either a rule config or the literal string 'sync'."""
558559

src/dve/core_engine/configuration/v1/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,29 +106,31 @@ class _LinkageConfig(BaseModel):
106106
"""The error code to emit if the entity has no valid records and is mandatory in the parent entity""" # pylint: disable=C0301
107107
no_valid_records_error_message: Optional[ErrorMessage] = (
108108
"parent record removed as no valid child records"
109-
)
109+
)
110110
"""The error message to emit if the entity has no valid records and is mandatory in the parent entity""" # pylint: disable=C0301
111111
missing_parent_id_error_code: Optional[ErrorCode] = "MissingParentRecord"
112112
"""The error code to emit if the entity contains records that are orphaned by parent record rejections""" # pylint: disable=C0301
113113
missing_parent_id_error_message: Optional[ErrorMessage] = (
114114
"Records removed due to no valid parent record"
115115
)
116116
"""The error code to emit if the entity contains records that are orphaned by parent record rejections""" # pylint: disable=C0301
117-
117+
118118
@model_validator(mode="after")
119119
def _check_root_no_parent_or_join_keys(self):
120120
if self.is_root_entity:
121121
if self.parent_entity or self.join_fields:
122-
raise ValueError("If entity is root, neither parent_entity nor join keys should be specified")
122+
raise ValueError(
123+
"If entity is root, neither parent_entity nor join keys should be specified"
124+
)
123125
return self
124-
126+
125127
@model_validator(mode="after")
126128
def _check_root_mandatory(self):
127129
if self.is_root_entity:
128130
if not self.mandatory:
129131
raise ValueError("If entity is root, it must be labelled mandatory")
130132
return self
131-
133+
132134
@model_validator(mode="after")
133135
def _check_parent_entity_with_join_keys(self):
134136
if self.parent_entity or self.join_fields:

src/dve/core_engine/configuration/v1/hierarchy.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
from typing import Any, Iterable, Optional, Union
55

6-
from pydantic import BaseModel, Field, field_validator
6+
from pydantic import BaseModel, Field
77

88
from dve.core_engine.configuration.v1 import V1EngineConfig, _LinkageConfig
99
from dve.core_engine.type_hints import EntityName, ErrorCode, ErrorMessage
@@ -16,18 +16,16 @@ class HierarchyNode(BaseModel):
1616
"""Stores entity hierarchy information"""
1717

1818
entity_name: str
19-
children: Optional[list["HierarchyNode"]] = Field(default_factory=list)
20-
mandatory: Optional[bool] = False
21-
join_fields: Optional[dict[str, str]] = Field(default_factory=dict)
22-
no_valid_records_error_code: Optional[ErrorCode] = "NoValidRecords"
23-
no_valid_records_error_message: Optional[ErrorMessage] = (
24-
"parent record removed as no valid child records"
25-
)
19+
children: list["HierarchyNode"] = Field(default_factory=list)
20+
mandatory: bool = False
21+
join_fields: dict[str, str] = Field(default_factory=dict)
22+
no_valid_records_error_code: ErrorCode = "NoValidRecords"
23+
no_valid_records_error_message: ErrorMessage = "parent record removed as no valid child records"
2624
missing_parent_id_error_code: Optional[ErrorCode] = "MissingParentRecord"
2725
missing_parent_id_error_message: Optional[ErrorMessage] = (
2826
"Records removed due to no valid parent record"
2927
)
30-
28+
3129
def get_descendents(self) -> list[str]:
3230
"""Recursively list all descendents of the node"""
3331
descendents = []
@@ -79,24 +77,34 @@ def determine_trees(
7977
all_datasets: Iterable[str], entity_relationships: dict[str, _LinkageConfig]
8078
) -> dict[EntityName, HierarchyNode]:
8179
"""Determine the entity hierarchy trees and store as HierarchyNodes"""
82-
root_entities: dict[str, _LinkageConfig] = dict(filter(lambda x: x[1].is_root_entity,
83-
entity_relationships.items()))
80+
root_entities: dict[str, _LinkageConfig] = dict(
81+
filter(lambda x: x[1].is_root_entity, entity_relationships.items())
82+
)
8483
top_level_parents: dict[EntityName, HierarchyNode] = {
85-
entity_name: HierarchyNode(entity_name=entity_name,
86-
**config.model_dump(exclude={"parent_entity",
87-
"missing_parent_id_error_code",
88-
"missing_parent_id_error_message"}),
89-
missing_parent_id_error_code=None,
90-
missing_parent_id_error_message=None)
84+
entity_name: HierarchyNode(
85+
entity_name=entity_name,
86+
**config.model_dump(
87+
exclude={
88+
"parent_entity",
89+
"missing_parent_id_error_code",
90+
"missing_parent_id_error_message",
91+
}
92+
),
93+
missing_parent_id_error_code=None,
94+
missing_parent_id_error_message=None,
95+
)
9196
for entity_name, config in root_entities.items()
9297
}
93-
94-
if default_roots := [ entity_name for entity_name in all_datasets
95-
if not entity_name in entity_relationships]:
98+
99+
if default_roots := [
100+
entity_name for entity_name in all_datasets if not entity_name in entity_relationships
101+
]:
96102
for entity_name in default_roots:
97-
top_level_parents[entity_name] = HierarchyNode(entity_name=entity_name,
98-
missing_parent_id_error_code=None,
99-
missing_parent_id_error_message=None)
103+
top_level_parents[entity_name] = HierarchyNode(
104+
entity_name=entity_name,
105+
missing_parent_id_error_code=None,
106+
missing_parent_id_error_message=None,
107+
)
100108

101109
for name, linkage_detail in entity_relationships.items():
102110
for main_entity, parent_node in top_level_parents.items():

0 commit comments

Comments
 (0)