Re: [sqlalchemy] dialect sensible declaration

2012-07-08 Thread alex bodnaru

it worked very well,

thanks a lot michael :),

alex

On 07/07/2012 05:13 PM, Michael Bayer wrote:
 sure engine and connection have .dialect.name.   Foreign key constraints 
 don't matter on SQLite unless you've actually enabled them, which is rare.   
 I'd still use an event though so at least the behavior is transparent.
 
 @event.listens_for(my_table, before_create)
 def add_fk(table, conn, **kw):
 if conn.dialect.name != 'mssql':
 table.append_constraint(ForeignKeyConstraint(...))
 
 tricky though to modify the table metadata within a create event in the 
 case that the table is created multiple times in an app.  you can put a flag 
 in table.info, like table.info['added_the_fk'] = True, to keep track of 
 things.
 
 
 
 On Jul 7, 2012, at 12:59 AM, alex bodnaru wrote:
 

 hello mike and thanks for your answer.

 no problem with ForeignKeyConstraint, but wouldn't AddConstraint go the alter
 way? in this case, it will be ignored by the sqlite dialect.

 what i was looking for was more like:

 from sqlalchemy... import get_dialect

 
 fk_parms = dict(.)
 if get_dialect() != 'mssql':
  fk_parms.update(onupdate='restrict')
 fk = ForeignKey(**fk_parms)

 would the dialect be accessible from the engine, metadata etc?

 thanks in advance,
 alex


 On 07/06/2012 11:39 PM, Michael Bayer wrote:
 you'd use ForeignKeyConstraint along with the AddConstraint directive, and 
 limit it per-dialect using create/drop events as documented at 
 http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#controlling-ddl-sequences
  .


 On Jul 6, 2012, at 1:30 PM, alex bodnaru wrote:


 hello friends,

 i need to define a foreign key differently for different dialects:
 ondelete='restrict' for most engines, but nothing (implied and not 
 recognized)
 for mssql.

 could you help?

 thanks in advance,
 alex

 -- 
 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.

 

-- 
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] Upgrade to 0.7.8 breaks code for query().all()

2012-07-08 Thread RedBaron
I have written some code on (I think) SqlAlchemy 0.7.5 on my office
computer and it works perfectly. Now I tried to run the same code on
my home computer and installed Sqlalchemy 0.7.8. However, the first
query statement returned an error InvalidRequestError: Select
statement 'SELECT count(%s) AS count_1  FROM event, signature AS
signature_1 WHERE event.signature = signature_1.sig_id' returned no
FROM clauses due to auto-correlation; specify correlate(tables) to
control correlation manually

The tables in question are
class SnortEvent(Base):
__tablename__=event

sid=Column(Integer,ForeignKey(sensor.sid),primary_key=True)
cid=Column(mysql.MSInteger(unsigned=True),primary_key=True)
signature=Column(Integer,ForeignKey(signature.sig_id))
timestamp=Column(DateTime)
isdel=Column('is_deleted',Boolean,default=False,nullable =False)
 
processed_event=relationship(ProcessedEvent,uselist=False,backref=backref(event,lazy='select'),cascade=all,delete-
orphan,lazy=False)
 
iphdr=relationship(IpHdr,uselist=False,backref=backref(event,lazy=True),cascade=all,delete-
orphan,lazy=False)
#id = column_property(sid,cid)
def __init__(self,sid,cid,sig,ts):
self.sid=sid
self.cid=self.cid
self.timestamp=ts
self.signature=sig

def __repr__(self):
return Alert:%d-%d%(self.sid,self.cid)


class Signature(Base):
__tablename__=signature

id=Column(sig_id,Integer,primary_key=True)
name=Column(sig_name,String(255))
 
class_id=Column(sig_class_id,Integer,ForeignKey(sig_class.sig_class_id))
sig_priority=Column(Integer)
sig_rev=Column(Integer)
sig_sid=Column(Integer)
sig_gid=Column(Integer)
 
references=relationship(SigReference,backref=sig,cascade=all,lazy=True)
 
events=relationship(SnortEvent,backref=backref(sig,lazy=False),cascade=all,delete-
orphan,lazy=joined,primaryjoin=Signature.id==SnortEvent.signature)
sig_count =
column_property(select([func.count('*'),]).where(SnortEvent.signature==id))


def __repr__(self):
return Signature:%s%(self.name)

The funny thing is that the error is raised if I try to use the all()
on query but slicing returns results just fine
 event = session.query(SnortEvent)
event = event[1:1000]
..A long list of events
event.all()
Above ERROR
event[:1100]
...Another long list
event[:]
Above ERROR

I frankly cannot guess the cause of the error(which was not there in
ver 0.7.5) or its absense in limited query
Any help is appreciated

-- 
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] Upgrade to 0.7.8 breaks code for query().all()

2012-07-08 Thread Michael Bayer
its a bug.  Here's a workaround, declare this outside of the Signature class:

Signature.sig_count = column_property(
select([func.count('*')]).\
where(SnortEvent.signature == Signature.id).\
correlate(Signature.__table__)
)



On Jul 8, 2012, at 12:32 PM, RedBaron wrote:

 I have written some code on (I think) SqlAlchemy 0.7.5 on my office
 computer and it works perfectly. Now I tried to run the same code on
 my home computer and installed Sqlalchemy 0.7.8. However, the first
 query statement returned an error InvalidRequestError: Select
 statement 'SELECT count(%s) AS count_1  FROM event, signature AS
 signature_1 WHERE event.signature = signature_1.sig_id' returned no
 FROM clauses due to auto-correlation; specify correlate(tables) to
 control correlation manually
 
 The tables in question are
 class SnortEvent(Base):
__tablename__=event
 
sid=Column(Integer,ForeignKey(sensor.sid),primary_key=True)
cid=Column(mysql.MSInteger(unsigned=True),primary_key=True)
signature=Column(Integer,ForeignKey(signature.sig_id))
timestamp=Column(DateTime)
isdel=Column('is_deleted',Boolean,default=False,nullable =False)
 
 processed_event=relationship(ProcessedEvent,uselist=False,backref=backref(event,lazy='select'),cascade=all,delete-
 orphan,lazy=False)
 
 iphdr=relationship(IpHdr,uselist=False,backref=backref(event,lazy=True),cascade=all,delete-
 orphan,lazy=False)
#id = column_property(sid,cid)
def __init__(self,sid,cid,sig,ts):
self.sid=sid
self.cid=self.cid
self.timestamp=ts
self.signature=sig
 
def __repr__(self):
return Alert:%d-%d%(self.sid,self.cid)
 
 
 class Signature(Base):
__tablename__=signature
 
id=Column(sig_id,Integer,primary_key=True)
name=Column(sig_name,String(255))
 
 class_id=Column(sig_class_id,Integer,ForeignKey(sig_class.sig_class_id))
sig_priority=Column(Integer)
sig_rev=Column(Integer)
sig_sid=Column(Integer)
sig_gid=Column(Integer)
 
 references=relationship(SigReference,backref=sig,cascade=all,lazy=True)
 
 events=relationship(SnortEvent,backref=backref(sig,lazy=False),cascade=all,delete-
 orphan,lazy=joined,primaryjoin=Signature.id==SnortEvent.signature)
sig_count =
 column_property(select([func.count('*'),]).where(SnortEvent.signature==id))
 
 
def __repr__(self):
return Signature:%s%(self.name)
 
 The funny thing is that the error is raised if I try to use the all()
 on query but slicing returns results just fine
 event = session.query(SnortEvent)
 event = event[1:1000]
 ..A long list of events
 event.all()
 Above ERROR
 event[:1100]
 ...Another long list
 event[:]
 Above ERROR
 
 I frankly cannot guess the cause of the error(which was not there in
 ver 0.7.5) or its absense in limited query
 Any help is appreciated
 
 -- 
 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.



Re: [sqlalchemy] Upgrade to 0.7.8 breaks code for query().all()

2012-07-08 Thread Michael Bayer
I have it appearing in 0.7.3, which would imply you're on 0.7.2 on the working 
system.


On Jul 8, 2012, at 2:31 PM, Michael Bayer wrote:

 its a bug.  Here's a workaround, declare this outside of the Signature class:
 
 Signature.sig_count = column_property(
select([func.count('*')]).\
where(SnortEvent.signature == Signature.id).\
correlate(Signature.__table__)
)
 
 
 
 On Jul 8, 2012, at 12:32 PM, RedBaron wrote:
 
 I have written some code on (I think) SqlAlchemy 0.7.5 on my office
 computer and it works perfectly. Now I tried to run the same code on
 my home computer and installed Sqlalchemy 0.7.8. However, the first
 query statement returned an error InvalidRequestError: Select
 statement 'SELECT count(%s) AS count_1  FROM event, signature AS
 signature_1 WHERE event.signature = signature_1.sig_id' returned no
 FROM clauses due to auto-correlation; specify correlate(tables) to
 control correlation manually
 
 The tables in question are
 class SnortEvent(Base):
   __tablename__=event
 
   sid=Column(Integer,ForeignKey(sensor.sid),primary_key=True)
   cid=Column(mysql.MSInteger(unsigned=True),primary_key=True)
   signature=Column(Integer,ForeignKey(signature.sig_id))
   timestamp=Column(DateTime)
   isdel=Column('is_deleted',Boolean,default=False,nullable =False)
 
 processed_event=relationship(ProcessedEvent,uselist=False,backref=backref(event,lazy='select'),cascade=all,delete-
 orphan,lazy=False)
 
 iphdr=relationship(IpHdr,uselist=False,backref=backref(event,lazy=True),cascade=all,delete-
 orphan,lazy=False)
   #id = column_property(sid,cid)
   def __init__(self,sid,cid,sig,ts):
   self.sid=sid
   self.cid=self.cid
   self.timestamp=ts
   self.signature=sig
 
   def __repr__(self):
   return Alert:%d-%d%(self.sid,self.cid)
 
 
 class Signature(Base):
   __tablename__=signature
 
   id=Column(sig_id,Integer,primary_key=True)
   name=Column(sig_name,String(255))
 
 class_id=Column(sig_class_id,Integer,ForeignKey(sig_class.sig_class_id))
   sig_priority=Column(Integer)
   sig_rev=Column(Integer)
   sig_sid=Column(Integer)
   sig_gid=Column(Integer)
 
 references=relationship(SigReference,backref=sig,cascade=all,lazy=True)
 
 events=relationship(SnortEvent,backref=backref(sig,lazy=False),cascade=all,delete-
 orphan,lazy=joined,primaryjoin=Signature.id==SnortEvent.signature)
   sig_count =
 column_property(select([func.count('*'),]).where(SnortEvent.signature==id))
 
 
   def __repr__(self):
   return Signature:%s%(self.name)
 
 The funny thing is that the error is raised if I try to use the all()
 on query but slicing returns results just fine
 event = session.query(SnortEvent)
 event = event[1:1000]
 ..A long list of events
 event.all()
 Above ERROR
 event[:1100]
 ...Another long list
 event[:]
 Above ERROR
 
 I frankly cannot guess the cause of the error(which was not there in
 ver 0.7.5) or its absense in limited query
 Any help is appreciated
 
 -- 
 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.
 

-- 
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] Upgrade to 0.7.8 breaks code for query().all()

2012-07-08 Thread Michael Bayer
yeah, actually, that's just what the behavior needs to be going forward, there 
are some improvements in 0.8 in that you'll be able to say 
correlate_except(SnortEvent), since you definitely don't want it correlated, so 
once that API is in place I'll add to the docs.

The situation is that by saying lazy=False, you're asking for SELECT event.*, 
sig_alias.*, (your subquery correlated against sig_alias) FROM event LEFT OUTER 
JOIN signature AS sig_alias   So it is natural that because event is in 
the FROM clause of the enclosing query, auto-correlation will want to remove 
event from the subquery.   So explicit definition of correlation is needed 
here, and should really be in all of these column_property() cases so the docs 
will be updated.



On Jul 8, 2012, at 2:35 PM, Michael Bayer wrote:

 I have it appearing in 0.7.3, which would imply you're on 0.7.2 on the 
 working system.
 
 
 On Jul 8, 2012, at 2:31 PM, Michael Bayer wrote:
 
 its a bug.  Here's a workaround, declare this outside of the Signature class:
 
 Signature.sig_count = column_property(
   select([func.count('*')]).\
   where(SnortEvent.signature == Signature.id).\
   correlate(Signature.__table__)
   )
 
 
 
 On Jul 8, 2012, at 12:32 PM, RedBaron wrote:
 
 I have written some code on (I think) SqlAlchemy 0.7.5 on my office
 computer and it works perfectly. Now I tried to run the same code on
 my home computer and installed Sqlalchemy 0.7.8. However, the first
 query statement returned an error InvalidRequestError: Select
 statement 'SELECT count(%s) AS count_1  FROM event, signature AS
 signature_1 WHERE event.signature = signature_1.sig_id' returned no
 FROM clauses due to auto-correlation; specify correlate(tables) to
 control correlation manually
 
 The tables in question are
 class SnortEvent(Base):
  __tablename__=event
 
  sid=Column(Integer,ForeignKey(sensor.sid),primary_key=True)
  cid=Column(mysql.MSInteger(unsigned=True),primary_key=True)
  signature=Column(Integer,ForeignKey(signature.sig_id))
  timestamp=Column(DateTime)
  isdel=Column('is_deleted',Boolean,default=False,nullable =False)
 
 processed_event=relationship(ProcessedEvent,uselist=False,backref=backref(event,lazy='select'),cascade=all,delete-
 orphan,lazy=False)
 
 iphdr=relationship(IpHdr,uselist=False,backref=backref(event,lazy=True),cascade=all,delete-
 orphan,lazy=False)
  #id = column_property(sid,cid)
  def __init__(self,sid,cid,sig,ts):
  self.sid=sid
  self.cid=self.cid
  self.timestamp=ts
  self.signature=sig
 
  def __repr__(self):
  return Alert:%d-%d%(self.sid,self.cid)
 
 
 class Signature(Base):
  __tablename__=signature
 
  id=Column(sig_id,Integer,primary_key=True)
  name=Column(sig_name,String(255))
 
 class_id=Column(sig_class_id,Integer,ForeignKey(sig_class.sig_class_id))
  sig_priority=Column(Integer)
  sig_rev=Column(Integer)
  sig_sid=Column(Integer)
  sig_gid=Column(Integer)
 
 references=relationship(SigReference,backref=sig,cascade=all,lazy=True)
 
 events=relationship(SnortEvent,backref=backref(sig,lazy=False),cascade=all,delete-
 orphan,lazy=joined,primaryjoin=Signature.id==SnortEvent.signature)
  sig_count =
 column_property(select([func.count('*'),]).where(SnortEvent.signature==id))
 
 
  def __repr__(self):
  return Signature:%s%(self.name)
 
 The funny thing is that the error is raised if I try to use the all()
 on query but slicing returns results just fine
 event = session.query(SnortEvent)
 event = event[1:1000]
 ..A long list of events
 event.all()
 Above ERROR
 event[:1100]
 ...Another long list
 event[:]
 Above ERROR
 
 I frankly cannot guess the cause of the error(which was not there in
 ver 0.7.5) or its absense in limited query
 Any help is appreciated
 
 -- 
 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.
 
 
 -- 
 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 

Re: [sqlalchemy] fractional second percision- mysql

2012-07-08 Thread James
Michael,

Thank you for your response. Your help is greatly appreciated. Just to be 
clear, are these changes that you have made and that I can access if I 
update to 0.7 or later? And would I simply need to specify the new FracTime 
type instead of Time?

Example:
 meta_timings = Table('meta_timings', metadata, 
   ... 
Column('elapsed', FracTime, nullable=False), 
  ...) 

--James

-- 
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/-/Xj8EoZp3NBkJ.
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] fractional second percision- mysql

2012-07-08 Thread Michael Bayer

On Jul 8, 2012, at 3:21 PM, James wrote:

 Michael,
 
 Thank you for your response. Your help is greatly appreciated. Just to be 
 clear, are these changes that you have made and that I can access if I update 
 to 0.7 or later? And would I simply need to specify the new FracTime type 
 instead of Time?

I have not made any changes, have only proposed some hypothetical changes for 
the 0.7 series.  I don't have this newest version of MySQL installed, so I was 
asking you to test the workaround I gave and/or the patch, to ensure it solves 
all the problems fully.  This testing would also establish that the MySQL DBAPI 
is properly receiving/returning the microseconds field.

If the workarounds I gave solve your problem fully, then I can commit the patch 
to SQLAlchemy and resolve that we are doing all that's needed for fractional 
time support.




 
 Example:
  meta_timings = Table('meta_timings', metadata, 
... 
 Column('elapsed', FracTime, nullable=False), 
   ...) 
 
 --James
 
 -- 
 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/-/Xj8EoZp3NBkJ.
 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] Alembic 0.3.5 Released

2012-07-08 Thread Michael Bayer
Hey all -

I've released Alembic 0.3.5. 

Alembic is a migration tool for SQLAlchemy, allowing the construction of 
incremental migration scripts which apply alterations to an existing schema 
or set of schemas.   It provides a very open-ended configuration model, plenty 
of API hooks for programmatic usage, and features such as automatic comparison 
of a schema to a metadata model and offline SQL generation.

0.3.5 includes these fixes:

0.3.5
=
- [bug] Fixed issue whereby reflected server defaults
  wouldn't be quoted correctly; uses repr() now.
  #31

- [bug] Fixed issue whereby when autogenerate would
  render create_table() on the upgrade side for a
  table that has a Boolean type, an unnecessary
  CheckConstraint() would be generated. #58

- [feature] Implemented SQL rendering for
  CheckConstraint() within autogenerate upgrade,
  including for literal SQL as well as SQL Expression
  Language expressions.

Read more about Alembic, and download Alembic 0.3.5 from the Python cheese shop 
at:

http://pypi.python.org/pypi/alembic/





-- 
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] Dialect-specific UserDefinedType variants

2012-07-08 Thread Jon Parise
I have a simple HStore(UserDefinedType) implementation that works well
with PostgreSQL.  I'd also like to provide a more generic HStore
implementation that can be used with SQLite for in-memory unit testing
databases.  That fallback implementation could be implemented in terms
of pickled or JSON-encoded dictionaries.

For my purposes, I'm only interested in bulk dictionary storage.  I
don't need a full hstore implementation complete with query language
support, etc.

What is the recommended way to expose these two specialized type
implementations?  It looks like the .with_variant() method might be
helpful here, but the documentation on type variants is slim enough
that I thought it best to ask here first.

-- 
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] Re: Upgrade to 0.7.8 breaks code for query().all()

2012-07-08 Thread RedBaron
Ah! Now I understand the genesis of the error and what I was doing
wrong. Many thanks for pointing that out. Yes I am indeed running
0.7.2. I'll test it on 0.7.8 and report back.
 Thanks again for clearing me up on correlation.


On Jul 9, 12:17 am, Michael Bayer mike...@zzzcomputing.com wrote:
 yeah, actually, that's just what the behavior needs to be going forward, 
 there are some improvements in 0.8 in that you'll be able to say 
 correlate_except(SnortEvent), since you definitely don't want it correlated, 
 so once that API is in place I'll add to the docs.

 The situation is that by saying lazy=False, you're asking for SELECT 
 event.*, sig_alias.*, (your subquery correlated against sig_alias) FROM event 
 LEFT OUTER JOIN signature AS sig_alias   So it is natural that because 
 event is in the FROM clause of the enclosing query, auto-correlation will 
 want to remove event from the subquery.   So explicit definition of 
 correlation is needed here, and should really be in all of these 
 column_property() cases so the docs will be updated.

 On Jul 8, 2012, at 2:35 PM, Michael Bayer wrote:







  I have it appearing in 0.7.3, which would imply you're on 0.7.2 on the 
  working system.

  On Jul 8, 2012, at 2:31 PM, Michael Bayer wrote:

  its a bug.  Here's a workaround, declare this outside of the Signature 
  class:

  Signature.sig_count = column_property(
                    select([func.count('*')]).\
                        where(SnortEvent.signature == Signature.id).\
                        correlate(Signature.__table__)
                )

  On Jul 8, 2012, at 12:32 PM, RedBaron wrote:

  I have written some code on (I think) SqlAlchemy 0.7.5 on my office
  computer and it works perfectly. Now I tried to run the same code on
  my home computer and installed Sqlalchemy 0.7.8. However, the first
  query statement returned an error InvalidRequestError: Select
  statement 'SELECT count(%s) AS count_1  FROM event, signature AS
  signature_1 WHERE event.signature = signature_1.sig_id' returned no
  FROM clauses due to auto-correlation; specify correlate(tables) to
  control correlation manually

  The tables in question are
  class SnortEvent(Base):
   __tablename__=event

   sid=Column(Integer,ForeignKey(sensor.sid),primary_key=True)
   cid=Column(mysql.MSInteger(unsigned=True),primary_key=True)
   signature=Column(Integer,ForeignKey(signature.sig_id))
   timestamp=Column(DateTime)
   isdel=Column('is_deleted',Boolean,default=False,nullable =False)

  processed_event=relationship(ProcessedEvent,uselist=False,backref=backref
   (event,lazy='select'),cascade=all,delete-
  orphan,lazy=False)

  iphdr=relationship(IpHdr,uselist=False,backref=backref(event,lazy=True)
   ,cascade=all,delete-
  orphan,lazy=False)
   #id = column_property(sid,cid)
   def __init__(self,sid,cid,sig,ts):
       self.sid=sid
       self.cid=self.cid
       self.timestamp=ts
       self.signature=sig

   def __repr__(self):
       return Alert:%d-%d%(self.sid,self.cid)

  class Signature(Base):
   __tablename__=signature

   id=Column(sig_id,Integer,primary_key=True)
   name=Column(sig_name,String(255))

  class_id=Column(sig_class_id,Integer,ForeignKey(sig_class.sig_class_id)
   )
   sig_priority=Column(Integer)
   sig_rev=Column(Integer)
   sig_sid=Column(Integer)
   sig_gid=Column(Integer)

  references=relationship(SigReference,backref=sig,cascade=all,lazy=Tru
   e)

  events=relationship(SnortEvent,backref=backref(sig,lazy=False),cascade=
   all,delete-
  orphan,lazy=joined,primaryjoin=Signature.id==SnortEvent.signature)
   sig_count =
  column_property(select([func.count('*'),]).where(SnortEvent.signature==id))

   def __repr__(self):
       return Signature:%s%(self.name)

  The funny thing is that the error is raised if I try to use the all()
  on query but slicing returns results just fine
  event = session.query(SnortEvent)
  event = event[1:1000]
  ..A long list of events
  event.all()
  Above ERROR
  event[:1100]
  ...Another long list
  event[:]
  Above ERROR

  I frankly cannot guess the cause of the error(which was not there in
  ver 0.7.5) or its absense in limited query
  Any help is appreciated

  --
  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 
  athttp://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 
  athttp://groups.google.com/group/sqlalchemy?hl=en.

  --
  You received this message because you are subscribed to the Google Groups 
  sqlalchemy group.