[sqlalchemy] Entity name - multiple schema - relationship
I need some help and advices to create a mapping. The context : - Multiple schemas on postgresql (dynamic number and name) who store the same tables. - SQLAlchemy used into a pyramid web application. Example : A table Customer and a table CustomerOrder (link by customer.id) and a schema by society (not know before running) I read the documentation about horizontal, vertical sharding and entity name but I'm a little bit confused about the good solution to solve my problem. If I use Entity name, I don't know how to configure the relationship between my two dynamic classes because I need to specify a class at configuration time but i really know the real subclasses only at runtime. If I use the Horizontal sharding, I need to have an engine / schema (and use search_path). The shard configurtion will be (or seems to be) tricky. If I use the Vertical sharding, I need also an engine / schema and re-configure the session several times with a new binds mapping. I made some google search with my context but it's not an usual case and i didn't find some helpful posts I also posed the question on stackoverflow last year but my solution don't really work : http://stackoverflow.com/questions/20212165/one-entity-in-multiple-schemas-how-to-switch-schema-on-runtime Thanks in advance. -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] Entity name - multiple schema - relationship
part of a feature that will make this kind of thing more direct is the schema name execution argument feature, which is https://bitbucket.org/zzzeek/sqlalchemy/issue/2685/default-schema-as-an-execution-argument. This application is somewhat of a multi-tenancy application; technically its horizontally partitioned but if you know society up front and for the duration of an operation, you can just set that and be done with it. Assuming this is the case an easy way to do this for now is just to set the search path on your postgresql connection before such an operation proceeds. That way when you refer to table X or Y, it will be in terms of whatever search path you've set, see 5.7.3 at http://www.postgresql.org/docs/8.1/static/ddl-schemas.html. There's no need in that case to use any kind of explicit horizontal sharding. Only if you need queries that are going to refer to multiple schemas at once does the HS feature come into play (and if that were the case I'd look into PG table inheritance). On May 5, 2014, at 8:41 AM, Julien Meyer julien.mey...@gmail.com wrote: I need some help and advices to create a mapping. The context : - Multiple schemas on postgresql (dynamic number and name) who store the same tables. - SQLAlchemy used into a pyramid web application. Example : A table Customer and a table CustomerOrder (link by customer.id) and a schema by society (not know before running) I read the documentation about horizontal, vertical sharding and entity name but I'm a little bit confused about the good solution to solve my problem. If I use Entity name, I don't know how to configure the relationship between my two dynamic classes because I need to specify a class at configuration time but i really know the real subclasses only at runtime. If I use the Horizontal sharding, I need to have an engine / schema (and use search_path). The shard configurtion will be (or seems to be) tricky. If I use the Vertical sharding, I need also an engine / schema and re-configure the session several times with a new binds mapping. I made some google search with my context but it's not an usual case and i didn't find some helpful posts I also posed the question on stackoverflow last year but my solution don't really work : http://stackoverflow.com/questions/20212165/one-entity-in-multiple-schemas-how-to-switch-schema-on-runtime Thanks in advance. -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Problem with _compiler_dispatch() call?
I get the following error when trying to create_all() in a sqlite database: TypeError: _compiler_dispatch() missing 1 required positional argument: 'visitor' Looking at annotation.py and visitors.py, all instances of _compiler_dispatch() do indeed appear to expect a 'visitor' argument, which is not provided in the type_._compiler_dispatch() call from TypeCompiler.process() in line 266 of compiler.py. The end of the traceback is below. I'm using SQLAlchemy 0.9.4, Python 3.4.0, and alchy 0.11.2. Thanks, Seth ... C:\Python34\lib\site-packages\sqlalchemy\sql\visitors.py in _compiler_dispatch(self, visitor, **kw) 77 raise exc.UnsupportedCompilationError(visitor, cls) 78 else: --- 79 return meth(self, **kw) 80 else: 81 # The optimization opportunity is lost for this case because the C:\Python34\lib\site-packages\sqlalchemy\sql\compiler.py in visit_create_column(self, create, first_pk) 2368 text = self.get_column_specification( 2369 column, - 2370 first_pk=first_pk 2371 ) 2372 const = .join(self.process(constraint) \ C:\Python34\lib\site-packages\sqlalchemy\dialects\sqlite\base.py in get_column_specification(self, column, **kwargs) 538 539 def get_column_specification(self, column, **kwargs): -- 540 coltype = self.dialect.type_compiler.process(column.type) 541 colspec = self.preparer.format_column(column) + + coltype 542 default = self.get_column_default_string(column) C:\Python34\lib\site-packages\sqlalchemy\sql\compiler.py in process(self, type_) 264 265 def process(self, type_): -- 266 return type_._compiler_dispatch(self) 267 268 C:\Python34\lib\site-packages\sqlalchemy\sql\visitors.py in _compiler_dispatch(self, visitor, **kw) 77 raise exc.UnsupportedCompilationError(visitor, cls) 78 else: --- 79 return meth(self, **kw) 80 else: 81 # The optimization opportunity is lost for this case because the C:\Python34\lib\site-packages\sqlalchemy\sql\compiler.py in visit_type_decorator(self, type_) 2755 2756 def visit_type_decorator(self, type_): - 2757 return self.process(type_.type_engine(self.dialect)) 2758 2759 def visit_user_defined(self, type_): C:\Python34\lib\site-packages\sqlalchemy\sql\compiler.py in process(self, type_) 264 265 def process(self, type_): -- 266 return type_._compiler_dispatch(self) 267 268 TypeError: _compiler_dispatch() missing 1 required positional argument: 'visitor' -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] Problem with _compiler_dispatch() call?
need to see the calling code on that, sounds like you might be using an API incorrectly. e.g. a short script which when run, produces this error - could be in table defs etc. On May 5, 2014, at 3:07 PM, Seth P spadow...@gmail.com wrote: I get the following error when trying to create_all() in a sqlite database: TypeError: _compiler_dispatch() missing 1 required positional argument: 'visitor' Looking at annotation.py and visitors.py, all instances of _compiler_dispatch() do indeed appear to expect a 'visitor' argument, which is not provided in the type_._compiler_dispatch() call from TypeCompiler.process() in line 266 of compiler.py. The end of the traceback is below. I'm using SQLAlchemy 0.9.4, Python 3.4.0, and alchy 0.11.2. Thanks, Seth ... C:\Python34\lib\site-packages\sqlalchemy\sql\visitors.py in _compiler_dispatch(self, visitor, **kw) 77 raise exc.UnsupportedCompilationError(visitor, cls) 78 else: --- 79 return meth(self, **kw) 80 else: 81 # The optimization opportunity is lost for this case because the C:\Python34\lib\site-packages\sqlalchemy\sql\compiler.py in visit_create_column(self, create, first_pk) 2368 text = self.get_column_specification( 2369 column, - 2370 first_pk=first_pk 2371 ) 2372 const = .join(self.process(constraint) \ C:\Python34\lib\site-packages\sqlalchemy\dialects\sqlite\base.py in get_column_specification(self, column, **kwargs) 538 539 def get_column_specification(self, column, **kwargs): -- 540 coltype = self.dialect.type_compiler.process(column.type) 541 colspec = self.preparer.format_column(column) + + coltype 542 default = self.get_column_default_string(column) C:\Python34\lib\site-packages\sqlalchemy\sql\compiler.py in process(self, type_) 264 265 def process(self, type_): -- 266 return type_._compiler_dispatch(self) 267 268 C:\Python34\lib\site-packages\sqlalchemy\sql\visitors.py in _compiler_dispatch(self, visitor, **kw) 77 raise exc.UnsupportedCompilationError(visitor, cls) 78 else: --- 79 return meth(self, **kw) 80 else: 81 # The optimization opportunity is lost for this case because the C:\Python34\lib\site-packages\sqlalchemy\sql\compiler.py in visit_type_decorator(self, type_) 2755 2756 def visit_type_decorator(self, type_): - 2757 return self.process(type_.type_engine(self.dialect)) 2758 2759 def visit_user_defined(self, type_): C:\Python34\lib\site-packages\sqlalchemy\sql\compiler.py in process(self, type_) 264 265 def process(self, type_): -- 266 return type_._compiler_dispatch(self) 267 268 TypeError: _compiler_dispatch() missing 1 required positional argument: 'visitor' -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Re: Problem with _compiler_dispatch() call?
Of course you are right. My problem code was basically the PythonEnum class in https://groups.google.com/d/topic/sqlalchemy/5yvdhl9ErMo/discussion. Deleting the *(m.name for m in enum_class), from the __init__ call seems to have fixed the problem. Thanks again. Seth On Monday, May 5, 2014 3:07:50 PM UTC-4, Seth P wrote: I get the following error when trying to create_all() in a sqlite database: TypeError: _compiler_dispatch() missing 1 required positional argument: 'visitor' Looking at annotation.py and visitors.py, all instances of _compiler_dispatch() do indeed appear to expect a 'visitor' argument, which is not provided in the type_._compiler_dispatch() call from TypeCompiler.process() in line 266 of compiler.py. The end of the traceback is below. I'm using SQLAlchemy 0.9.4, Python 3.4.0, and alchy 0.11.2. Thanks, Seth ... C:\Python34\lib\site-packages\sqlalchemy\sql\visitors.py in _compiler_dispatch(self, visitor, **kw) 77 raise exc.UnsupportedCompilationError(visitor, cls) 78 else: --- 79 return meth(self, **kw) 80 else: 81 # The optimization opportunity is lost for this case because the C:\Python34\lib\site-packages\sqlalchemy\sql\compiler.py in visit_create_column(self, create, first_pk) 2368 text = self.get_column_specification( 2369 column, - 2370 first_pk=first_pk 2371 ) 2372 const = .join(self.process(constraint) \ C:\Python34\lib\site-packages\sqlalchemy\dialects\sqlite\base.py in get_column_specification(self, column, **kwargs) 538 539 def get_column_specification(self, column, **kwargs): -- 540 coltype = self.dialect.type_compiler.process(column.type) 541 colspec = self.preparer.format_column(column) + + coltype 542 default = self.get_column_default_string(column) C:\Python34\lib\site-packages\sqlalchemy\sql\compiler.py in process(self, type_) 264 265 def process(self, type_): -- 266 return type_._compiler_dispatch(self) 267 268 C:\Python34\lib\site-packages\sqlalchemy\sql\visitors.py in _compiler_dispatch(self, visitor, **kw) 77 raise exc.UnsupportedCompilationError(visitor, cls) 78 else: --- 79 return meth(self, **kw) 80 else: 81 # The optimization opportunity is lost for this case because the C:\Python34\lib\site-packages\sqlalchemy\sql\compiler.py in visit_type_decorator(self, type_) 2755 2756 def visit_type_decorator(self, type_): - 2757 return self.process(type_.type_engine(self.dialect)) 2758 2759 def visit_user_defined(self, type_): C:\Python34\lib\site-packages\sqlalchemy\sql\compiler.py in process(self, type_) 264 265 def process(self, type_): -- 266 return type_._compiler_dispatch(self) 267 268 TypeError: _compiler_dispatch() missing 1 required positional argument: 'visitor' -- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.