Skip to content

Commit 3876a01

Browse files
authored
Fix a bug causing stale page ID to be set even after deleting the page (baserow#4937)
1 parent cba51ac commit 3876a01

File tree

6 files changed

+89
-2
lines changed

6 files changed

+89
-2
lines changed

backend/src/baserow/contrib/builder/elements/element_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ def deserialize_property(
831831
**kwargs,
832832
) -> Any:
833833
if prop_name == "navigate_to_page_id" and value:
834-
return id_mapping["builder_pages"][value]
834+
return id_mapping["builder_pages"].get(value)
835835

836836
return value
837837

backend/src/baserow/contrib/builder/workflow_actions/registries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def deserialize_property(
9999

100100
# Migrate page id
101101
if prop_name == "page_id":
102-
return id_mapping["builder_pages"][value]
102+
return id_mapping["builder_pages"].get(value)
103103

104104
# Migrate element id
105105
if prop_name == "element_id":

backend/tests/baserow/contrib/builder/elements/test_link_collection_field_type.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,63 @@ def test_import_export_link_collection_field_type(data_fixture):
141141
"target": "self",
142142
"variant": LinkElement.VARIANTS.LINK,
143143
}
144+
145+
146+
@pytest.mark.django_db
147+
def test_import_link_collection_field_with_stale_page_id(data_fixture):
148+
"""
149+
Ensure that importing a link collection field doesn't crash when
150+
the navigate_to_page_id is provided but doesn't exist.
151+
"""
152+
153+
user, _ = data_fixture.create_user_and_token()
154+
page = data_fixture.create_builder_page(user=user)
155+
table, fields, _ = data_fixture.build_table(
156+
user=user,
157+
columns=[
158+
("Name", "text"),
159+
],
160+
rows=[
161+
["Foo"],
162+
],
163+
)
164+
data_source = data_fixture.create_builder_local_baserow_list_rows_data_source(
165+
table=table, page=page
166+
)
167+
table_element = data_fixture.create_builder_table_element(
168+
page=page,
169+
data_source=data_source,
170+
fields=[
171+
{
172+
"name": "Foo Link Field",
173+
"type": "link",
174+
"config": {
175+
"link_name": "'Buy some gold!'",
176+
"navigate_to_url": "'https://www.kitco.com'",
177+
"navigation_type": "custom",
178+
"navigate_to_page_id": 100,
179+
"page_parameters": [],
180+
"query_parameters": [],
181+
"target": "self",
182+
"variant": LinkElement.VARIANTS.LINK,
183+
},
184+
},
185+
],
186+
)
187+
188+
duplicated_page = PageService().duplicate_page(user, page)
189+
data_source2 = duplicated_page.datasource_set.first()
190+
id_mapping = {
191+
"builder_data_sources": {data_source.id: data_source2.id},
192+
# the invalid page 100 isn't included
193+
"builder_pages": {},
194+
}
195+
196+
exported = table_element.get_type().export_serialized(table_element)
197+
# This shouldn't fail if page 100 isn't in the mapping
198+
imported_table_element = table_element.get_type().import_serialized(
199+
page, exported, id_mapping
200+
)
201+
imported_field = imported_table_element.fields.get(name="Foo Link Field")
202+
assert imported_field.config["navigate_to_page_id"] is None
203+
assert imported_field.config["navigation_type"] == "custom"

backend/tests/baserow/contrib/builder/workflow_actions/test_workflow_action_types.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,20 @@ def test_builder_workflow_action_type_dispatch(workflow_action):
418418
instance.dispatch(mock_workflow_action, mock_dispatch_context)
419419

420420
assert str(e.value) == "This service cannot be dispatched."
421+
422+
423+
def test_workflow_action_type_deserialize_property_with_stale_page_id():
424+
"""
425+
Ensure that deserializing a workflow action with an invalid page ID
426+
doesn't cause a crash.
427+
"""
428+
429+
action_type = OpenPageWorkflowActionType()
430+
id_mapping = {"builder_pages": {}}
431+
432+
# This shouldn't fail when the page ID doesn't exist
433+
result = action_type.deserialize_property("page_id", 100, id_mapping)
434+
assert result is None
435+
436+
result = action_type.deserialize_property("navigate_to_page_id", 100, id_mapping)
437+
assert result is None
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "bug",
3+
"message": "Fixed a bug that could cause a stale page ID to be set even after deleting the page.",
4+
"issue_origin": "github",
5+
"issue_number": null,
6+
"domain": "builder",
7+
"bullet_points": [],
8+
"created_at": "2026-03-06"
9+
}

web-frontend/modules/builder/components/elements/components/forms/general/LinkNavigationSelectionForm.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export default {
189189
this.values.navigate_to_url = ''
190190
} else if (value === 'custom') {
191191
this.values.navigation_type = 'custom'
192+
this.values.navigate_to_page_id = null
192193
} else if (!isNaN(value)) {
193194
this.values.navigation_type = 'page'
194195
this.values.navigate_to_page_id = value

0 commit comments

Comments
 (0)