Skip to content

Commit

Permalink
Allowed external="STREAM:" keys to not be represented in data in Comp…
Browse files Browse the repository at this point in the history
…oseEvent and ComposeEventPage
  • Loading branch information
evalott100 committed Jul 4, 2023
1 parent 19e6744 commit 010c410
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions event_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2249,11 +2249,16 @@ def __call__(
)
if validate:
schema_validators[DocumentNames.event_page].validate(doc)

if not (
self.descriptor["data_keys"].keys() == data.keys() == timestamps.keys()
keys_without_stream_keys(
self.descriptor["data_keys"], self.descriptor["data_keys"]
) ==
keys_without_stream_keys(data, self.descriptor["data_keys"]) ==
keys_without_stream_keys(timestamps, self.descriptor["data_keys"])
):
raise EventModelValidationError(
"These sets of keys must match:\n"
"These sets of keys must match (other than \"STREAM:\" keys):\n"
"event['data'].keys(): {}\n"
"event['timestamps'].keys(): {}\n"
"descriptor['data_keys'].keys(): {}\n".format(
Expand Down Expand Up @@ -2295,6 +2300,16 @@ def compose_event_page(
time=time,
validate=validate,
)


def keys_without_stream_keys(dictionary, descriptor_data_keys):
return [
key for key in dictionary.keys() if (
"external" not in descriptor_data_keys[key] or
descriptor_data_keys[key]["external"] != "STREAM:"
)
]



@dataclass
Expand Down Expand Up @@ -2331,11 +2346,16 @@ def __call__(
)
if validate:
schema_validators[DocumentNames.event].validate(doc)

if not (
self.descriptor["data_keys"].keys() == data.keys() == timestamps.keys()
keys_without_stream_keys(
self.descriptor["data_keys"], self.descriptor["data_keys"]
) ==
keys_without_stream_keys(data, self.descriptor["data_keys"]) ==
keys_without_stream_keys(timestamps, self.descriptor["data_keys"])
):
raise EventModelValidationError(
"These sets of keys must match:\n"
"These sets of keys must match (other than \"STREAM:\" keys):\n"
"event['data'].keys(): {}\n"
"event['timestamps'].keys(): {}\n"
"descriptor['data_keys'].keys(): {}\n".format(
Expand Down

0 comments on commit 010c410

Please sign in to comment.