Skip to content

Comments

Update wis2 message formatting#289

Open
Teddy-1000 wants to merge 3 commits intomainfrom
update-wis2-message-formatting
Open

Update wis2 message formatting#289
Teddy-1000 wants to merge 3 commits intomainfrom
update-wis2-message-formatting

Conversation

@Teddy-1000
Copy link
Collaborator

Some updates to conform to wis2 message formatting.
Also makes it possible to set the data_id for wis2.

@github-actions
Copy link

Title Coverage Tests Skipped Failures Errors Time
API Unit Tests Coverage 40 0 💤 0 ❌ 0 🔥 1.556s ⏱️
Ingest Unit Tests Coverage 16 0 💤 0 ❌ 0 🔥 2.194s ⏱️

Comment on lines 2 to 4
# pip-compile --upgrade --no-emit-index-url
# Install using:
# pip-sync
Copy link
Contributor

@fjugipe fjugipe Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm all up for using uv and dropping pip-tools as you've done now in this PR. But I also think that the team should standardize on one tool since they might resolve dependencies slightly differently.

So probably would be beneficial to change these to:

# uv pip compile requirements.in -o requirements.txt --upgrade --no-emit-index-url
# Install using:
# uv pip sync requirements.txt

And the same for requirements-dev.in

@@ -103,7 +103,9 @@ async def publish_messages(self, messages: list, publishWIS2: bool, baseURL: str
if publishWIS2 and self.WIS2_client:
send_message(
generate_wis2_topic(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not part of the PR, but as the topic is very much static, maybe it should not be called every time a message is published or at least minimize the overhead if we want to keep the ValueError raising?

What if we change the generate_wis2_topic() to something like:

_WIS2_TOPIC = None

def generate_wis2_topic() -> str:
    """This function will generate the WIS2 compliant topic name"""
    global _WIS2_TOPIC
    if _WIS2_TOPIC is None:
        _WIS2_TOPIC = os.getenv("WIS2_TOPIC")
        if not _WIS2_TOPIC:
            raise ValueError("WIS2_TOPIC env variable not set. Aborting publish to wis2")
    return _WIS2_TOPIC

"Cached" version should be significantly faster because it does not make a os.getenv() dictionary lookup every time and as the messages will be in the millions per day, it matters.

integrity: Optional[Integrity] = Field(None, exclude_from_schema=True)

@model_validator(mode="after")
def set_dateimte(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def set_dateimte(self):
def set_datetime(self):

Comment on lines +54 to 56
data_id=os.getenv("WIS2_DATA_ID") or message["properties"]["data_id"],
metadata_id=os.getenv(
"WIS2_METADATA_RECORD_ID", None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These env variables could also be cached

)
content: Optional[Content] = Field(..., description="Actual data content")
metadata_id: Optional[str] = Field(
...,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be metadata_id: Optional[str] = Field(None, description="..." for it to be optional, right?

Field(..., ...) makes it required.

@model_validator(mode="after")
def set_dateimte(self):
assert bool(self.datetime) != bool(self.start_datetime and self.end_datetime), (
"Set datetime or start_datetime and end_datetime. At least one and not both. "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a bit clearer that it needs to be either datetime OR start_datetime and end_datetime. Maybe its just me, but the "At least one and not both" to be sounds like it could also be just the end_time which contradicts the assert.

So what about:
"Set either 'datetime' OR both 'start_datetime' and 'end_datetime', not both options."

Copy link
Contributor

@fjugipe fjugipe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some fixes to wis2_model.py & possible optimizations related to env variables. Also thoughts on using uv in the future.

Comment on lines 30 to 32
## Dev install

To install in dev mode run `pip install --editable .` from the top level of this repository.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the one tool standardization.

Suggested change
## Dev install
This project uses **uv** for dependency management.
To install in dev mode run `uv pip install -e .` from the top level of this repository.


class Integrity(BaseModel):
method: Literal["sha256", "sha384", "sha512", "sha3-256", "sha3-384", "sha3-512"]
value: str = Field(..., desciption="The hash value for the value field in the message content.")
Copy link
Contributor

@fjugipe fjugipe Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed a typo here also.

Suggested change
value: str = Field(..., description="The hash value for the value field in the message content.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants