Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/infrahub/core/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import netaddr
import ujson
from infrahub_sdk.timestamp import TimestampFormatError
from infrahub_sdk.exceptions import TimestampFormatError
from infrahub_sdk.utils import is_valid_url
from infrahub_sdk.uuidt import UUIDT
from pydantic import BaseModel, Field
Expand Down
10 changes: 5 additions & 5 deletions backend/infrahub/core/diff/model/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from neo4j.graph import Node as Neo4jNode
from neo4j.graph import Path as Neo4jPath
from neo4j.graph import Relationship as Neo4jRelationship
from pendulum import Interval
from whenever import TimeDelta
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to get rid of this import as well, if we can map it to a TimeDelta from our own TimeStamp class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agreed but it sounds like a bigger effort


from infrahub.graphql.initialization import GraphqlContext

Expand Down Expand Up @@ -417,8 +417,8 @@ def __hash__(self) -> int:
return hash(self.uuid)

@property
def time_range(self) -> Interval:
return self.to_time.obj - self.from_time.obj
def time_range(self) -> TimeDelta:
return self.to_time.get_obj() - self.from_time.get_obj()

def update_metadata(
self,
Expand Down Expand Up @@ -447,8 +447,8 @@ def __hash__(self) -> int:
return hash(self.uuid)

@property
def time_range(self) -> Interval:
return self.to_time.obj - self.from_time.obj
def time_range(self) -> TimeDelta:
Copy link
Contributor

Choose a reason for hiding this comment

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

As per the updates in the SDK the time_range here and on line 420 will raise a deprecation warning due to us keeping the code in the function intact.

return self.to_time.obj - self.from_time.obj

We don't want to use ._obj instead but perhaps we need some other method. Or some dundermethods on our own class so that it's possible to instead run:

return self.to_time - self.from_time

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, I fixed it

return self.to_time.get_obj() - self.from_time.get_obj()

def get_nodes_without_parents(self) -> set[EnrichedDiffNode]:
nodes_with_parent_uuids = set()
Expand Down
6 changes: 3 additions & 3 deletions backend/infrahub/core/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from infrahub_sdk.timestamp import Timestamp as BaseTimestamp

if TYPE_CHECKING:
from pendulum.datetime import DateTime
from datetime import datetime


class Timestamp(BaseTimestamp):
async def to_graphql(self, *args: Any, **kwargs: Any) -> DateTime: # noqa: ARG002
return self.obj
async def to_graphql(self, *args: Any, **kwargs: Any) -> datetime: # noqa: ARG002
return self.to_datetime()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this method used anywhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes


def get_query_filter_path(self, rel_name: str = "r") -> tuple[str, dict]:
"""
Expand Down
25 changes: 15 additions & 10 deletions backend/infrahub/graphql/queries/diff/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def to_diff_node(self, enriched_node: EnrichedDiffNode, graphql_context: Graphql
label=enriched_node.label,
status=enriched_node.action,
parent=parent,
last_changed_at=enriched_node.changed_at.obj if enriched_node.changed_at else None,
last_changed_at=enriched_node.changed_at.to_datetime() if enriched_node.changed_at else None,
path_identifier=enriched_node.path_identifier,
attributes=diff_attributes,
relationships=diff_relationships,
Expand All @@ -219,7 +219,7 @@ def to_diff_attribute(
diff_prop.conflict = None
return DiffAttribute(
name=enriched_attribute.name,
last_changed_at=enriched_attribute.changed_at.obj,
last_changed_at=enriched_attribute.changed_at.to_datetime(),
status=enriched_attribute.action,
path_identifier=enriched_attribute.path_identifier,
properties=diff_properties,
Expand All @@ -241,7 +241,9 @@ def to_diff_relationship(
return DiffRelationship(
name=enriched_relationship.name,
label=enriched_relationship.label,
last_changed_at=enriched_relationship.changed_at.obj if enriched_relationship.changed_at else None,
last_changed_at=enriched_relationship.changed_at.to_datetime()
if enriched_relationship.changed_at
else None,
status=enriched_relationship.action,
cardinality=enriched_relationship.cardinality,
path_identifier=enriched_relationship.path_identifier,
Expand All @@ -263,7 +265,7 @@ def to_diff_relationship_element(
enriched_conflict=enriched_element.conflict, graphql_context=graphql_context
)
return DiffSingleRelationship(
last_changed_at=enriched_element.changed_at.obj,
last_changed_at=enriched_element.changed_at.to_datetime(),
status=enriched_element.action,
peer_id=enriched_element.peer_id,
peer_label=enriched_element.peer_label,
Expand All @@ -287,7 +289,7 @@ def to_diff_property(
)
return DiffProperty(
property_type=enriched_property.property_type.value,
last_changed_at=enriched_property.changed_at.obj,
last_changed_at=enriched_property.changed_at.to_datetime(),
previous_value=enriched_property.previous_value,
new_value=enriched_property.new_value,
previous_label=enriched_property.previous_label,
Expand All @@ -306,13 +308,13 @@ def to_diff_conflict(
uuid=enriched_conflict.uuid,
base_branch_action=enriched_conflict.base_branch_action,
base_branch_value=enriched_conflict.base_branch_value,
base_branch_changed_at=enriched_conflict.base_branch_changed_at.obj
base_branch_changed_at=enriched_conflict.base_branch_changed_at.to_datetime()
if enriched_conflict.base_branch_changed_at
else None,
base_branch_label=enriched_conflict.base_branch_label,
diff_branch_action=enriched_conflict.diff_branch_action,
diff_branch_value=enriched_conflict.diff_branch_value,
diff_branch_changed_at=enriched_conflict.diff_branch_changed_at.obj
diff_branch_changed_at=enriched_conflict.diff_branch_changed_at.to_datetime()
if enriched_conflict.diff_branch_changed_at
else None,
diff_branch_label=enriched_conflict.diff_branch_label,
Expand Down Expand Up @@ -426,7 +428,10 @@ async def resolve(
# take the one with the longest duration that covers multiple branches
enriched_diff = sorted(
enriched_diffs,
key=lambda d: (d.base_branch_name != d.diff_branch_name, d.to_time.obj - d.from_time.obj),
key=lambda d: (
d.base_branch_name != d.diff_branch_name,
d.to_time.to_datetime() - d.from_time.to_datetime(),
),
reverse=True,
)[0]
else:
Expand Down Expand Up @@ -485,8 +490,8 @@ async def summary(
diff_tree_summary = DiffTreeSummary(
base_branch=base_branch.name,
diff_branch=diff_branch.name,
from_time=summary.from_time.obj,
to_time=summary.to_time.obj,
from_time=summary.from_time.to_datetime(),
to_time=summary.to_time.to_datetime(),
**summary.model_dump(exclude={"from_time", "to_time"}),
)
full_fields = await extract_fields(info.field_nodes[0].selection_set)
Expand Down
2 changes: 1 addition & 1 deletion backend/infrahub/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from fastapi.responses import RedirectResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from infrahub_sdk.timestamp import TimestampFormatError
from infrahub_sdk.exceptions import TimestampFormatError
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from opentelemetry.trace import Span
from pydantic import ValidationError
Expand Down
4 changes: 2 additions & 2 deletions backend/infrahub/task_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ def from_filters(
) -> InfrahubEventFilter:
occurred_filter = {}
if since:
occurred_filter["since"] = Timestamp(since.isoformat()).obj
occurred_filter["since"] = Timestamp(since.isoformat()).to_datetime()

if until:
occurred_filter["until"] = Timestamp(until.isoformat()).obj
occurred_filter["until"] = Timestamp(until.isoformat()).to_datetime()

if occurred_filter:
filters = cls(occurred=EventOccurredFilter(**occurred_filter))
Expand Down
8 changes: 4 additions & 4 deletions backend/tests/integration/user_workflows/test_user_worflow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pendulum
import pytest
from deepdiff import DeepDiff
from whenever import Instant

from infrahub.database import InfrahubDatabase
from infrahub.graphql.manager import GraphQLSchemaManager
Expand Down Expand Up @@ -251,7 +251,7 @@ async def test_query_all_devices(self, test_client, integration_helper):
if device["node"]["name"]["value"] == "spine1":
state.data["spine1_id"] = device["node"]["id"]
# Initialize the start time
state.data["time_start"] = pendulum.now(tz="UTC")
state.data["time_start"] = Instant.now()

async def test_query_spine1_loobpack0(self, test_client, integration_helper):
"""
Expand Down Expand Up @@ -374,7 +374,7 @@ async def test_update_intf_description_branch1(

assert intfs[0]["node"]["description"]["value"] == new_description

state.data["time_after_intf_update_branch1"] = pendulum.now("UTC").to_iso8601_string()
state.data["time_after_intf_update_branch1"] = Instant.now().format_common_iso()

async def test_update_intf_description_main(self, test_client, integration_helper):
"""
Expand Down Expand Up @@ -781,7 +781,7 @@ async def test_query_spine1_lo0_at_start_time(self, test_client, integration_hel
"intf_name": intf_name,
},
},
params={"at": state.data["time_start"].to_iso8601_string()},
params={"at": state.data["time_start"].format_common_iso()},
headers=headers,
)
assert response.status_code == 200
Expand Down
Loading
Loading