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 6e8a865
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 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 @@ -2297,6 +2302,15 @@ def compose_event_page(
)


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
class ComposeEvent:
descriptor: EventDescriptor
Expand Down Expand Up @@ -2331,11 +2345,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 6e8a865

Please sign in to comment.