Hi, I'm using a custom session class to route requests to different database engines based on the type of action being performed. Master for writes; slave for reads. It looks my attributes on my models expire immediately after creation. Anyway to prevent this? Or should I not worry about preventing it the expiration?
Session class: class RoutedSession(Session): def execute(self, *args, **kwargs): return super().execute(*args, **kwargs, use_master=True) def get_bind(self, mapper=None, clause=None, use_master=False): if use_master or self._flushing: return ENGINES['master'] return random.choice(ENGINES['slaves']) Application code: model = MyModel() session.add(model) session.commit() print(model.id) # ObjectDeletedError: Instance '<Model at 0x...>' has been deleted, or its row is otherwise not present. Traceback: File "tests/mock.py", line 2414, in populate_db_with_mock_data contact_id=contact2.id, account_id=account.id, File "sqlalchemy/orm/attributes.py", line 275, in __get__ return self.impl.get(instance_state(instance), dict_) File "sqlalchemy/orm/attributes.py", line 669, in get value = state._load_expired(state, passive) File "sqlalchemy/orm/state.py", line 632, in _load_expired self.manager.deferred_scalar_loader(self, toload) File "sqlalchemy/orm/loading.py", line 985, in load_scalar_attributes raise orm_exc.ObjectDeletedError(state) -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/7409fb50-53b3-4505-bb2c-e81d8002ecba%40googlegroups.com.