Hi guys
I tried to implement horizontal sharding
<http://docs.sqlalchemy.org/en/latest/orm/extensions/horizontal_shard.html>
in my project. Everything is ok, except bulk_inserts.
When I run tests, I got this error:
File "/home/anton/Projects/proj/core/model/messages.py", line 210, in
create
Session.bulk_insert_mappings(MessageEntity, to_commit)
File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/scoping.py", line 157,
in do
return getattr(self.registry(), name)(*args, **kwargs)
File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line 2345,
in bulk_insert_mappings
mapper, mappings, False, False, return_defaults, False)
File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line 2416,
in _bulk_save_mappings
transaction.rollback(_capture_exception=True)
File "build/bdist.linux-x86_64/egg/sqlalchemy/util/langhelpers.py", line
60, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line 2411,
in _bulk_save_mappings
mapper, mappings, transaction, isstates, return_defaults)
File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/persistence.py", line
35, in _bulk_insert
"connection_callable / per-instance sharding "
NotImplementedError: connection_callable / per-instance sharding not
supported in bulk_insert()
I do not understand what 'connection_callable' does, but I really need to
implement it. Is there any ways to do it?
If it can help: I ALWAYS perform UPDATE/INSERT/DELETE and most of SELECT
queries in only one database. So, I wrote such subclass:
class ShardedSessionWithDefaultBind(ShardedSession):
def get_bind(self, mapper, shard_id=None, instance=None, clause=None, **kw):
if shard_id is None:
shard_id = default_shard_id
return super(ShardedSessionWithDefaultBind, self).get_bind(mapper,
shard_id, instance, clause, **kw)
Maybe I can override "__init__" for my class and write
"self.connnection_callable = None"?
My research of sqlalchemy code didn't make me sure that it is safe enough.
But I see, that "connection_callable" used only for checking into
"_bulk_insert" and "_bulk_update" functions in sqlalchemy.orm.persistence
module.
So, if I 100% sure, that I ALWAYS perform INSERT/UPDATE/DELETE queries in
only one database, can I make it?
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.