Skip to content

Commit fffdb8d

Browse files
authored
Preparing for WA beta. (baserow#4189)
* Preparing for WA beta. * Reintroducing Instance.compat_type to ensure that we still support our old node types for compat reasons. * Revert the periodic type name. * Post rebase linting * Show the automation settings modal, but only show the General sidepanel in development. * Fix e2e test
1 parent 86cc8e6 commit fffdb8d

30 files changed

+395
-289
lines changed

backend/src/baserow/contrib/automation/nodes/handler.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from django.core.files.storage import Storage
55
from django.db.models import QuerySet
66

7+
from opentelemetry import trace
8+
79
from baserow.contrib.automation.automation_dispatch_context import (
810
AutomationDispatchContext,
911
)
@@ -30,10 +32,13 @@
3032
from baserow.core.services.handler import ServiceHandler
3133
from baserow.core.services.models import Service
3234
from baserow.core.storage import ExportZipFile
35+
from baserow.core.telemetry.utils import baserow_trace_methods
3336
from baserow.core.utils import ChildProgressBuilder, MirrorDict, extract_allowed
3437

38+
tracer = trace.get_tracer(__name__)
39+
3540

36-
class AutomationNodeHandler:
41+
class AutomationNodeHandler(metaclass=baserow_trace_methods(tracer)):
3742
allowed_fields = [
3843
"label",
3944
"service",
@@ -107,11 +112,12 @@ def invalidate_node_cache(self, workflow):
107112
local_cache.delete(self._get_node_cache_key(workflow, True))
108113
local_cache.delete(self._get_node_cache_key(workflow, False))
109114

110-
def get_children(self, node, specific=True):
115+
def get_children(self, node: AutomationNode) -> List[AutomationNode]:
111116
"""
112117
Returns the direct children of the given node.
113118
114-
:param specific: Whether to return specific node instances.
119+
:param node: The parent node.
120+
:return: A list of node instances that are the children of the given node.
115121
"""
116122

117123
return node.workflow.get_graph().get_children(node)
@@ -250,7 +256,7 @@ def import_node(
250256
) -> AutomationNode:
251257
"""
252258
Creates an instance of AutomationNode using the serialized version
253-
previously exported with `.export_node'.
259+
previously exported with '.export_node'.
254260
255261
:param workflow: The workflow instance the new node should
256262
belong to.

backend/src/baserow/contrib/automation/nodes/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ def get_next_nodes(
146146

147147
return self.workflow.get_graph().get_next_nodes(self, output_uid)
148148

149-
def get_children(self, specific=True):
149+
def get_children(self):
150150
"""
151151
Returns the direct children of this node if any.
152152
"""
153153

154154
from baserow.contrib.automation.nodes.handler import AutomationNodeHandler
155155

156-
return AutomationNodeHandler().get_children(self, specific=specific)
156+
return AutomationNodeHandler().get_children(self)
157157

158158

159159
class AutomationActionNode(AutomationNode):

backend/src/baserow/contrib/automation/nodes/node_types.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def before_move(
102102
output: str,
103103
):
104104
"""
105-
Check the container node is not moved inside it self.
105+
Check the container node is not moved inside itself.
106106
"""
107107

108108
if node in reference_node.get_parent_nodes():
@@ -114,7 +114,8 @@ def before_move(
114114

115115

116116
class LocalBaserowUpsertRowNodeType(AutomationNodeActionNodeType):
117-
type = "upsert_row"
117+
type = "local_baserow_upsert_row"
118+
compat_type = "upsert_row"
118119
service_type = LocalBaserowUpsertRowServiceType.type
119120

120121
def get_pytest_params(self, pytest_data_fixture) -> Dict[str, int]:
@@ -123,35 +124,41 @@ def get_pytest_params(self, pytest_data_fixture) -> Dict[str, int]:
123124

124125

125126
class LocalBaserowCreateRowNodeType(LocalBaserowUpsertRowNodeType):
126-
type = "create_row"
127+
type = "local_baserow_create_row"
128+
compat_type = "create_row"
127129
model_class = LocalBaserowCreateRowActionNode
128130

129131

130132
class LocalBaserowUpdateRowNodeType(LocalBaserowUpsertRowNodeType):
131-
type = "update_row"
133+
type = "local_baserow_update_row"
134+
compat_type = "update_row"
132135
model_class = LocalBaserowUpdateRowActionNode
133136

134137

135138
class LocalBaserowDeleteRowNodeType(AutomationNodeActionNodeType):
136-
type = "delete_row"
139+
type = "local_baserow_delete_row"
140+
compat_type = "delete_row"
137141
model_class = LocalBaserowDeleteRowActionNode
138142
service_type = LocalBaserowDeleteRowServiceType.type
139143

140144

141145
class LocalBaserowGetRowNodeType(AutomationNodeActionNodeType):
142-
type = "get_row"
146+
type = "local_baserow_get_row"
147+
compat_type = "get_row"
143148
model_class = LocalBaserowGetRowActionNode
144149
service_type = LocalBaserowGetRowUserServiceType.type
145150

146151

147152
class LocalBaserowListRowsNodeType(AutomationNodeActionNodeType):
148-
type = "list_rows"
153+
type = "local_baserow_list_rows"
154+
compat_type = "list_rows"
149155
model_class = LocalBaserowListRowsActionNode
150156
service_type = LocalBaserowListRowsUserServiceType.type
151157

152158

153159
class LocalBaserowAggregateRowsNodeType(AutomationNodeActionNodeType):
154-
type = "aggregate_rows"
160+
type = "local_baserow_aggregate_rows"
161+
compat_type = "aggregate_rows"
155162
model_class = LocalBaserowAggregateRowsActionNode
156163
service_type = LocalBaserowAggregateRowsUserServiceType.type
157164

@@ -365,19 +372,22 @@ def on_event(
365372

366373

367374
class LocalBaserowRowsCreatedNodeTriggerType(AutomationNodeTriggerType):
368-
type = "rows_created"
375+
type = "local_baserow_rows_created"
376+
compat_type = "rows_created"
369377
model_class = LocalBaserowRowsCreatedTriggerNode
370378
service_type = LocalBaserowRowsCreatedServiceType.type
371379

372380

373381
class LocalBaserowRowsUpdatedNodeTriggerType(AutomationNodeTriggerType):
374-
type = "rows_updated"
382+
type = "local_baserow_rows_updated"
383+
compat_type = "rows_updated"
375384
model_class = LocalBaserowRowsUpdatedTriggerNode
376385
service_type = LocalBaserowRowsUpdatedServiceType.type
377386

378387

379388
class LocalBaserowRowsDeletedNodeTriggerType(AutomationNodeTriggerType):
380-
type = "rows_deleted"
389+
type = "local_baserow_rows_deleted"
390+
compat_type = "rows_deleted"
381391
model_class = LocalBaserowRowsDeletedTriggerNode
382392
service_type = LocalBaserowRowsDeletedServiceType.type
383393

backend/src/baserow/contrib/automation/workflows/graph_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def get_next_nodes(
250250
if output is None or uid == output
251251
]
252252

253-
def get_children(self, node) -> List[AutomationNode]:
253+
def get_children(self, node: AutomationNode) -> List[AutomationNode]:
254254
"""
255255
Returns the node children.
256256
"""

backend/src/baserow/contrib/automation/workflows/handler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from django.utils import timezone
1212

1313
from loguru import logger
14+
from opentelemetry import trace
1415

1516
from baserow.contrib.automation.automation_dispatch_context import (
1617
AutomationDispatchContext,
@@ -48,6 +49,7 @@
4849
from baserow.core.registries import ImportExportConfig
4950
from baserow.core.services.exceptions import DispatchException
5051
from baserow.core.storage import ExportZipFile, get_default_storage
52+
from baserow.core.telemetry.utils import baserow_trace_methods
5153
from baserow.core.trash.handler import TrashHandler
5254
from baserow.core.utils import (
5355
ChildProgressBuilder,
@@ -60,8 +62,10 @@
6062
WORKFLOW_RATE_LIMIT_CACHE_PREFIX = "automation_workflow_{}"
6163
AUTOMATION_WORKFLOW_CACHE_LOCK_SECONDS = 5
6264

65+
tracer = trace.get_tracer(__name__)
6366

64-
class AutomationWorkflowHandler:
67+
68+
class AutomationWorkflowHandler(metaclass=baserow_trace_methods(tracer)):
6569
allowed_fields = ["name", "allow_test_run_until", "state"]
6670

6771
def get_workflow(

backend/src/baserow/core/registry.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class Instance(object):
5252
type: str
5353
"""A unique string that identifies the instance."""
5454

55+
compat_type: str = ""
56+
""" If this instance has been renamed, and we want to support
57+
compatibility of the original `type`, implement it with `compat_type`. """
58+
5559
def __init__(self):
5660
if not self.type:
5761
raise ImproperlyConfigured("The type of an instance must be set.")
@@ -758,13 +762,29 @@ def get(self, type_name: str) -> InstanceSubClass:
758762
:rtype: InstanceModelInstance
759763
"""
760764

765+
# If the `type_name` isn't in the registry, we may raise DoesNotExist.
761766
if type_name not in self.registry:
762-
raise self.does_not_exist_exception_class(
763-
type_name, f"The {self.name} type {type_name} does not exist."
764-
)
767+
# But first, we'll test to see if it matches an Instance's
768+
# `compat_name`. If it does, we'll use that Instance's `type`.
769+
type_name_via_compat = self.get_by_type_name_by_compat(type_name)
770+
if type_name_via_compat:
771+
type_name = type_name_via_compat
772+
else:
773+
raise self.does_not_exist_exception_class(
774+
type_name, f"The {self.name} type {type_name} does not exist."
775+
)
765776

766777
return self.registry[type_name]
767778

779+
def get_by_type_name_by_compat(self, compat_name: str) -> Optional[str]:
780+
"""
781+
Returns a registered instance's `type` by using the compatibility name.
782+
"""
783+
784+
for instance in self.get_all():
785+
if instance.compat_type == compat_name:
786+
return instance.type
787+
768788
def get_by_type(self, instance_type: Type[InstanceSubClass]) -> InstanceSubClass:
769789
return self.get(instance_type.type)
770790

0 commit comments

Comments
 (0)