eschutho commented on code in PR #41176:
URL: https://github.com/apache/superset/pull/41176#discussion_r3554084333


##########
superset/versioning/baseline/collection.py:
##########
@@ -0,0 +1,153 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Discovery: figure out which parents need a baseline row.
+
+Three helpers cooperate on the listener's "should I baseline" decision:
+
+* :func:`collect_parents_to_baseline` — walks ``session.dirty`` /
+  ``new`` / ``deleted`` and returns the unique parent entities to
+  consider (directly-dirty versioned parents + parents reachable from
+  dirty children via :func:`child_to_parent_registry`).
+* :func:`version_table_for` — resolves a Continuum shadow Table for
+  one parent object.
+* :func:`shadow_row_count` — counts existing shadow rows for the
+  parent's id; ``0`` is the signal to insert a baseline.
+
+:func:`child_to_parent_registry` is also exposed because
+:mod:`superset.versioning.factory` consumes it via inline import.
+
+**Inline imports.** ``versioning.baseline`` is imported during
+``init_versioning()`` before all SQLAlchemy mappers are configured;
+the lazy imports defer Continuum + model resolution until call time.
+"""
+
+from __future__ import annotations
+
+import functools
+import logging
+from typing import Any
+
+import sqlalchemy as sa
+from sqlalchemy.exc import OperationalError, ProgrammingError
+from sqlalchemy.orm import Session
+
+# Populated at app startup (superset/initialization/__init__.py) before
+# register_baseline_listener() is called.
+VERSIONED_MODELS: list[type] = []
+
+logger = logging.getLogger(__name__)
+
+
+def collect_parents_to_baseline(session: Session) -> dict[int, Any]:
+    """Return parents-to-baseline as ``{id(obj): obj}`` keyed by Python
+    object identity to dedupe across ``session.dirty + new + deleted``.
+
+    Includes both directly-dirty versioned parents and parents reachable
+    from dirty/new/deleted children via the child→parent registry.
+    """
+    parents: dict[int, Any] = {}
+    child_map = child_to_parent_registry()
+    for obj in list(session.dirty) + list(session.new) + list(session.deleted):
+        if type(obj) in VERSIONED_MODELS:
+            parents[id(obj)] = obj

Review Comment:
   can you use get here instead of grabbing the value directly with the key?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to