[sqlalchemy] how to replace selectable but not with original table alias?
Hello. Is it possible to replace some table with defferent one? I want to get the same query, with the same columns, having, order_by, where clauses but with different table name. s.replace_selectable(t1, t1_alias) - works s.replace_selectable(t1, t2) - doesn't Thanks. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] how to replace selectable but not with original table alias?
replace_selectable can only swap in another selectable that's derived from the original. Else there's no way to correlate columns between each. you can try doing it directly, where the column correlation is by name (something SQLAlchemy doesn't ever do): from sqlalchemy.sql import visitors def replace(x): if x is t1:# replace the table return t2 elif t1.c.contains_column(x): # replace columns in the table return t2.c[x.key] s = visitors.replacement_traverse(s, {}, replace) There also are compilation ways to do this, building a subclass of Alias which compiles to the new name without the AS, this would be a little hacky. I also might be looking to adjust my application to not require a pattern like this. Here it would likely mean varying between t1 and t2 before s is created. On Oct 12, 2011, at 8:32 AM, sector119 wrote: Hello. Is it possible to replace some table with defferent one? I want to get the same query, with the same columns, having, order_by, where clauses but with different table name. s.replace_selectable(t1, t1_alias) - works s.replace_selectable(t1, t2) - doesn't Thanks. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] mapped attribute throws AttributeError: 'symbol' object has no attribute
When I try to access a specific mapped attribute the error below is thrown but only if I use a custom __eq__(). def __eq__(self, other): ''' ''' return self.aromatic_ring_id == other.aromatic_ring_id When I print the type of both, the 'other' class is 'symbol': class 'credoscript.models.aromaticring.AromaticRing' class 'sqlalchemy.util.langhelpers.symbol' Any ideas what went wrong? --- AttributeErrorTraceback (most recent call last) /home/adrian/ipython console in module() /usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.7.2-py2.7-linux-x86_64.egg/sqlalchemy/orm/attributes.pyc in __get__(self, instance, owner) 166 return dict_[self.key] 167 else: -- 168 return self.impl.get(instance_state(instance),dict_) 169 170 def create_proxied_attribute(descriptor): /usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.7.2-py2.7-linux-x86_64.egg/sqlalchemy/orm/attributes.pyc in get(self, state, dict_, passive) 422 value = ATTR_EMPTY 423 -- 424 if value in (PASSIVE_NO_RESULT, NEVER_SET): 425 return value 426 elif value is ATTR_WAS_SET: /home/adrian/Software/credoscript/models/aromaticring.py in __eq__(self, other) 48 ''' 49 print type(self), type(other) --- 50 return self.aromatic_ring_id == other.aromatic_ring_id 51 52 def __ne__(self, other): AttributeError: 'symbol' object has no attribute 'aromatic_ring_id' -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/3kqkVsvmxQ8J. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] mapped attribute throws AttributeError: 'symbol' object has no attribute
Please try out the dev tip, 0.7.3, which is at http://hg.sqlalchemy.org/sqlalchemy/archive/default.tar.gz . There's been a fix regarding attribute access upon objects that redefine __eq__(), which should never be called by SQLAlchemy and this looks like exactly that same issue. On Oct 12, 2011, at 11:17 AM, Adrian wrote: When I try to access a specific mapped attribute the error below is thrown but only if I use a custom __eq__(). def __eq__(self, other): ''' ''' return self.aromatic_ring_id == other.aromatic_ring_id When I print the type of both, the 'other' class is 'symbol': class 'credoscript.models.aromaticring.AromaticRing' class 'sqlalchemy.util.langhelpers.symbol' Any ideas what went wrong? --- AttributeErrorTraceback (most recent call last) /home/adrian/ipython console in module() /usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.7.2-py2.7-linux-x86_64.egg/sqlalchemy/orm/attributes.pyc in __get__(self, instance, owner) 166 return dict_[self.key] 167 else: -- 168 return self.impl.get(instance_state(instance),dict_) 169 170 def create_proxied_attribute(descriptor): /usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.7.2-py2.7-linux-x86_64.egg/sqlalchemy/orm/attributes.pyc in get(self, state, dict_, passive) 422 value = ATTR_EMPTY 423 -- 424 if value in (PASSIVE_NO_RESULT, NEVER_SET): 425 return value 426 elif value is ATTR_WAS_SET: /home/adrian/Software/credoscript/models/aromaticring.py in __eq__(self, other) 48 ''' 49 print type(self), type(other) --- 50 return self.aromatic_ring_id == other.aromatic_ring_id 51 52 def __ne__(self, other): AttributeError: 'symbol' object has no attribute 'aromatic_ring_id' -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/3kqkVsvmxQ8J. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.