fix: pass tenant extension to worker MemoryEngine for correct schema context (#236)
The worker loaded the tenant extension for the poller (schema discovery) but did not pass it to MemoryEngine. When execute_task set _current_schema via the _schema field, _authenticate_tenant would immediately reset it to "public" because self._tenant_extension was None, causing all worker writes to land in the public schema instead of the tenant schema. Move load_extension() before MemoryEngine creation and pass tenant_extension to the constructor.
This commit is contained in:
parent
15540075b2
commit
9c95a1ac1d
1 changed files with 7 additions and 3 deletions
|
|
@ -183,21 +183,25 @@ def main():
|
|||
|
||||
from ..extensions import TenantExtension, load_extension
|
||||
|
||||
# Load tenant extension BEFORE creating MemoryEngine so it can
|
||||
# set correct schema context during task execution. Without this,
|
||||
# _authenticate_tenant sees no extension and resets schema to "public",
|
||||
# causing worker writes to land in the wrong schema.
|
||||
tenant_extension = load_extension("TENANT", TenantExtension)
|
||||
|
||||
# Initialize MemoryEngine
|
||||
# Workers use SyncTaskBackend because they execute tasks directly,
|
||||
# they don't need to store tasks (they poll from DB)
|
||||
memory = MemoryEngine(
|
||||
run_migrations=False, # Workers don't run migrations
|
||||
task_backend=SyncTaskBackend(),
|
||||
tenant_extension=tenant_extension,
|
||||
)
|
||||
|
||||
await memory.initialize()
|
||||
|
||||
print(f"Database connected: {config.database_url}")
|
||||
|
||||
# Load tenant extension for dynamic schema discovery
|
||||
tenant_extension = load_extension("TENANT", TenantExtension)
|
||||
|
||||
if tenant_extension:
|
||||
print("Tenant extension loaded - schemas will be discovered dynamically on each poll")
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in a new issue