Skip to content

Commit

Permalink
fix for dumper logic with new line col metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
pblankley committed Apr 24, 2024
1 parent 33e5a86 commit 25ff77e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions metrics_layer/core/model/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ def collect_errors(self):
errors.append(self._error(self._definition.get("slice_by"), err_msg))

for f in self._raw_filters():
if not self._function_executes(self.project.get_field, f["field"]):
if not self._function_executes(self.project.get_field, f.get("field")):
err_msg = (
f"Could not find field {f['field']} referenced"
f"Could not find field {f.get('field')} referenced"
f" in a filter in dashboard {self.dashboard.name}"
)
errors.append(self._error(self._definition.get("filters"), err_msg))
Expand Down
17 changes: 11 additions & 6 deletions metrics_layer/core/parse/project_reader_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
class Str(ruamel.yaml.scalarstring.ScalarString):
__slots__ = "lc"

style = ""

def __new__(cls, value):
return ruamel.yaml.scalarstring.ScalarString.__new__(cls, value)


class ZenlyticPreservedScalarString(ruamel.yaml.scalarstring.PreservedScalarString):
__slots__ = "lc"
Expand Down Expand Up @@ -116,11 +111,21 @@ def read_yaml_file(path: str):
yaml_dict = yaml.load(f)
return yaml_dict

@staticmethod
def repr_str(representer, data):
return representer.represent_str(str(data))

@staticmethod
def dump_yaml_file(data: dict, path: str):
yaml = ruamel.yaml.YAML(typ="rt")
yaml.Constructor = ZenlyticConstructor
yaml.representer.add_representer(Str, ProjectReaderBase.repr_str)
yaml.representer.add_representer(ZenlyticPreservedScalarString, ProjectReaderBase.repr_str)
yaml.representer.add_representer(ZenlyticDoubleQuotedScalarString, ProjectReaderBase.repr_str)
yaml.representer.add_representer(ZenlyticSingleQuotedScalarString, ProjectReaderBase.repr_str)
filtered_data = {k: v for k, v in data.items() if not k.startswith("_")}
with open(path, "w") as f:
ruamel.yaml.dump(filtered_data, f, Dumper=ruamel.yaml.RoundTripDumper)
yaml.dump(filtered_data, f)

def load(self) -> None:
raise NotImplementedError()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "metrics_layer"
version = "0.12.8"
version = "0.12.9"
description = "The open source metrics layer."
authors = ["Paul Blankley <[email protected]>"]
keywords = ["Metrics Layer", "Business Intelligence", "Analytics"]
Expand Down

0 comments on commit 25ff77e

Please sign in to comment.