Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 4ebce28

Browse files
author
Sergey Vasilyev
committed
Fix the aftermath of refactoring: temporarily break compiler-database dependency loop
1 parent 2f12e38 commit 4ebce28

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

data_diff/databases/base.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,11 @@ class CompileError(Exception):
9090
pass
9191

9292

93-
# TODO: LATER: Resolve the circular imports of databases-compiler-dialects:
94-
# A database uses a compiler to render the SQL query.
95-
# The compiler delegates to a dialect.
96-
# The dialect renders the SQL.
97-
# AS IS: The dialect requires the db to normalize table paths — leading to the back-dependency.
98-
# TO BE: All the tables paths must be pre-normalized before SQL rendering.
99-
# Also: c.database.is_autocommit in render_commit().
100-
# After this, the Compiler can cease referring Database/Dialect at all,
101-
# and be used only as a CompilingContext (a counter/data-bearing class).
102-
# As a result, it becomes low-level util, and the circular dependency auto-resolves.
103-
# Meanwhile, the easy fix is to simply move the Compiler here.
93+
# TODO: remove once switched to attrs, where ForwardRef[]/strings are resolved.
94+
class _RuntypeHackToFixCicularRefrencedDatabase:
95+
dialect: "BaseDialect"
96+
97+
10498
@dataclass
10599
class Compiler(AbstractCompiler):
106100
"""
@@ -113,7 +107,7 @@ class Compiler(AbstractCompiler):
113107
# Database is needed to normalize tables. Dialect is needed for recursive compilations.
114108
# In theory, it is many-to-many relations: e.g. a generic ODBC driver with multiple dialects.
115109
# In practice, we currently bind the dialects to the specific database classes.
116-
database: "Database"
110+
database: _RuntypeHackToFixCicularRefrencedDatabase
117111

118112
in_select: bool = False # Compilation runtime flag
119113
in_join: bool = False # Compilation runtime flag
@@ -125,7 +119,7 @@ class Compiler(AbstractCompiler):
125119
_counter: List = field(default_factory=lambda: [0])
126120

127121
@property
128-
def dialect(self) -> "Dialect":
122+
def dialect(self) -> "BaseDialect":
129123
return self.database.dialect
130124

131125
# TODO: DEPRECATED: Remove once the dialect is used directly in all places.
@@ -844,7 +838,7 @@ def __getitem__(self, i):
844838
return self.rows[i]
845839

846840

847-
class Database(abc.ABC):
841+
class Database(abc.ABC, _RuntypeHackToFixCicularRefrencedDatabase):
848842
"""Base abstract class for databases.
849843
850844
Used for providing connection code and implementation specific SQL utilities.

0 commit comments

Comments
 (0)