fix: leave unused service fields out of every agent trigger (#6876)

This commit is contained in:
Peter Evans authored and GitHub committed 2026-11-26 10:53:20 +00:00
1 parent ed9eb7d3a7
commit dafe8ebf2e
4 files changed
+51 -3

No files matched your search

@@ -154,7 +154,9 @@ class AgentTriggerHandler:
"""
Prepare the values a trigger's service is created or updated with, as an
Agent hosts its type: a new service starts with the Agent's defaults for
the type, and the fields an Agent doesn't use are left out.
the type, and the fields an Agent doesn't use are left out. A trigger acts
as the Agent's run identity, never through an integration, so whatever its
type an ``integration_id`` is left out too.
:param service_type: The trigger service type the service has.
:param service_values: The values to set, by field name.
@@ -167,10 +169,11 @@ class AgentTriggerHandler:
trigger_type = agent_trigger_type_registry.get_for_service_type(
service_type.type
)
unused_fields = {"integration_id", *trigger_type.unused_service_fields}
values = {
name: value
for name, value in service_values.items()
if name not in trigger_type.unused_service_fields
if name not in unused_fields
}
if service is None:
values = {**trigger_type.default_service_values, **values}
@@ -14,6 +14,7 @@ class AgentTriggerType(Instance):
# The values a new service of the type starts with, unless others are given.
default_service_values: dict[str, Any] = {}
# The service fields only another consumer uses, which stay at their defaults.
# No type lists `integration_id`: the handler leaves it out for all of them.
unused_service_fields: tuple[str, ...] = ()
def __init__(self, service_type_name: str | None = None) -> None:
@@ -957,6 +957,51 @@ def test_a_row_trigger_is_refused_a_table_its_run_identity_cannot_read(
)
@pytest.mark.django_db
@pytest.mark.parametrize(
"owner", ["another application", "another workspace", "nothing"]
)
def test_a_row_trigger_leaves_out_any_integration_it_is_given(
data_fixture, api_client, api_user, owner
):
agent, table = agent_reading_orders(data_fixture, api_user)
if owner == "another application":
integration_id = data_fixture.create_local_baserow_integration(
application=data_fixture.create_builder_application(
workspace=agent.workspace
),
user=api_user,
).id
elif owner == "another workspace":
integration_id = data_fixture.create_local_baserow_integration().id
else:
integration_id = 2147483647
service = {"table_id": table.id, "integration_id": integration_id}
periodic = data_fixture.create_agent_trigger(agent=agent)
created = api_client.post(
agent_url(agent, "triggers:list"),
{"type": ROWS_CREATED, "message": MESSAGE, "service": service},
)
assert created.status_code == 200, created.json()
updated = api_client.patch(
agent_url(agent, "triggers:item", trigger_id=created.json()["id"]),
{"service": service},
)
changed = api_client.patch(
agent_url(agent, "triggers:item", trigger_id=periodic.id),
{"type": ROWS_CREATED, "service": service},
)
for response in (created, updated, changed):
assert response.status_code == 200, response.json()
assert response.json()["service"]["integration_id"] is None
assert response.json()["service"]["table_id"] == table.id
assert list(
LocalBaserowRowsCreated.objects.values_list("integration_id", flat=True)
) == [None, None]
@pytest.mark.django_db
def test_a_row_trigger_cannot_switch_on_once_its_run_identity_is_gone(
data_fixture, api_client, api_user
@@ -12,7 +12,6 @@ from baserow_enterprise.integrations.local_baserow.service_types import (
class RowCommentPostedAgentTriggerType(AgentTriggerType):
type = LocalBaserowRowCommentPostedTriggerServiceType.type
unused_service_fields = ("integration_id",)
def get_event_text(
self, service: LocalBaserowRowCommentPosted, event_payload: dict[str, Any]