Skip to content

Commit

Permalink
fix(hybridcloud) Clear lookup state during initialization (#50166)
Browse files Browse the repository at this point in the history
This avoids leaking state between instances of the SiloRouter which was
impacting getsentry tests.
  • Loading branch information
markstory committed Jun 2, 2023
1 parent 7df243e commit 87aeab5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/sentry/db/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SiloRouter:
"""Whether or not we're operating in a simulated silo environment"""

def __init__(self):
self.__table_to_silo = {}
try:
# By accessing the connections Django will raise
# Use `assert` to appease linters
Expand Down Expand Up @@ -89,7 +90,9 @@ def _db_for_table(self, table, app_label):
# have to scan through models more than once.
self.__table_to_silo[table] = self._db_for_model(model)

return self.__table_to_silo[table]
# All actively used tables should be in this map, but we also
# need to handle tables in migrations that no longer exist.
return self.__table_to_silo.get(table, "default")

def db_for_read(self, model, **hints):
return self._db_for_model(model)
Expand Down
5 changes: 5 additions & 0 deletions tests/sentry/db/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def test_for_control(self):
assert router.allow_migrate("control", "sentry", User)
assert not router.allow_migrate("region", "sentry", User)

# Ensure tables that no longer exist don't fail
assert router.allow_migrate(
"default", "sentry", model=None, hints={"tables": ["jira_ac_tenant"]}
)

@override_settings(SILO_MODE="REGION")
def test_for_region(self):
router = SiloRouter()
Expand Down

0 comments on commit 87aeab5

Please sign in to comment.