Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: cannot update attributes with name "updated_at" #3730

Closed
fatih-acar opened this issue Jun 28, 2024 · 2 comments
Closed

bug: cannot update attributes with name "updated_at" #3730

fatih-acar opened this issue Jun 28, 2024 · 2 comments
Labels
group/backend Issue related to the backend (API Server, Git Agent) type/bug Something isn't working as expected

Comments

@fatih-acar
Copy link
Contributor

fatih-acar commented Jun 28, 2024

Component

API Server / GraphQL
Infrahub 0.14.2

Current Behavior

When using a schema defining nodes that have an attribute named updated_at, it is not possible to change the value of this attribute and it is always blank/null.

Expected Behavior

updated_at attributes should be editable as expected

Steps to Reproduce

Load the following schema:

---
version: "1.0"
nodes:
  - name: Country
    namespace: Otterbox
    label: Country
    attributes:
      - name: name
        kind: Text
        unique: true
        optional: false
      - name: created_at
        kind: DateTime
        optional: false
      - name: updated_at
        kind: DateTime
        optional: false

Create a new Country node with a name, created_at and updated_at set.
You will see that created_at is correctly set but updated_at is not.

Additional Information

No response

@fatih-acar fatih-acar added the type/bug Something isn't working as expected label Jun 28, 2024
@dgarros dgarros added the group/backend Issue related to the backend (API Server, Git Agent) label Jul 5, 2024
@exalate-issue-sync exalate-issue-sync bot added the state/backlog This issue is part of the backlog label Jul 19, 2024
@ogenstad ogenstad added this to the Infrahub - 0.16.1 milestone Sep 18, 2024
@ogenstad
Copy link
Contributor

Added to 0.16.1 provided that this is a quick fix. I think it should be enough with this change:

diff --git a/backend/infrahub/core/node/__init__.py b/backend/infrahub/core/node/__init__.py
index 54ca35c52..502ed7d52 100644
--- a/backend/infrahub/core/node/__init__.py
+++ b/backend/infrahub/core/node/__init__.py
@@ -263,6 +263,8 @@ class Node(BaseNode, metaclass=BaseNodeMeta):
         # -------------------------------------------
         # Validate Input
         # -------------------------------------------
+        if "updated_at" in fields and "updated_at" not in self._schema.valid_input_names:
+            fields.pop("updated_at")
         for field_name in fields.keys():
             if field_name not in self._schema.valid_input_names:
                 errors.append(ValidationError({field_name: f"{field_name} is not a valid input for {self.get_kind()}"}))
@@ -422,6 +424,7 @@ class Node(BaseNode, metaclass=BaseNodeMeta):
         self._existing = True

         if updated_at:
+            kwargs["updated_at"] = updated_at
             self._updated_at = Timestamp(updated_at)

If this causes other problems we could perhaps move this to another milestone.

The problem is that we use an "updated_at" argument within the Node class to set the old metadata field _updated_at. The end goal would be to have correct metadata properties for each node where you as a user would be able to see when a node was created and when it was last updated. Even with that in place we shouldn't limit users from using the attribute name updated_at.

@dgarros
Copy link
Collaborator

dgarros commented Sep 21, 2024

Fixed in #4370

@dgarros dgarros closed this as completed Sep 21, 2024
@exalate-issue-sync exalate-issue-sync bot removed the state/backlog This issue is part of the backlog label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
group/backend Issue related to the backend (API Server, Git Agent) type/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

3 participants