[sqlalchemy] Re: how could a foreign key reference a unique (non pk) column combination?

2008-10-01 Thread alex bodnaru

i found it in alchemy:

ForeignKeyConstraint(['invoice_id', 'ref_num'],
['invoices.invoice_id', 'invoices.ref_num'])

posted on elixir list too, but expressing it in elixir would help a
lot, too :) .

thanks

On Wed, Oct 1, 2008 at 9:26 AM, alex bodnaru [EMAIL PROTECTED] wrote:
 hello friends,

 how could a foreign key reference a unique (but not primary kyey)
 column combination?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] how could a foreign key reference a unique (non pk) column combination?

2008-10-01 Thread alex bodnaru

hello friends,

how could a foreign key reference a unique (but not primary kyey)
column combination?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Instance added to session and flushed by backref before save() is actually called

2008-10-01 Thread Adam Dziendziel

I have a ContentObject class mapped using:

co_mapper = orm.mapper(ContentObject,
   content_objects_table,
   extension=COMapperExtension(),
   polymorphic_on=content_objects_table.c.type,
   polymorphic_identity='ContentObject',
   properties={
'theme': orm.relation(Theme),
'resources': orm.relation(Resource,
  secondary=co_resources_table),
'children': orm.relation(ContentObject,
secondary=co_children_table,
 
primaryjoin=content_objects_table.c.id==co_children_table.c.parent_id,
 
secondaryjoin=co_children_table.c.child_id==content_objects_table.c.id,
backref='parents'),
'translations': orm.relation(ContentObjectTranslation,
backref='co')
   }
)

co = ContentObject()
co.children.append(Session.query(ContentObject).get(1))
# assert co not in Session # fails!
co.theme = Session.query(Theme).get(1) # Session flushes automatically
when retrieving a theme, and I get an error because the  theme_id
column (with nullable=False) is not set yet

IntegrityError: (IntegrityError) content_objects.theme_id may not be
NULL u'INSERT INTO content_objects (type, parent_id, position,
theme_id, data, keywords) VALUES (?, ?, ?, ?, ?, ?)' ['group', None,
None, None, None, '']

If I remove backref='parents' it works as expected. Do I have to turn
auto-flush off to avoid incidental flushes?


Best regards,
Adam

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: unions in query?

2008-10-01 Thread az

answering myself, well... for the record.

 i'm back into my hierachy/graph of objects, which has many paths
 reaching from one end to another - A-Z, A-B-Z, A-B-C-Z etc. Using
 hierarchical OR (AND (OR ...))) works but gets very slow as all the
 20+ tables involved go in same FROM clause.

 so i have these questions:
  - (theoretical) can the alternative made by many ORs over
 subexpressions at same level be represented with UNION of things
 made from those subexpressions?
yes. the difference is in magnitudes, and moreover, union' space grows 
slowly/linearly while the other grows exponentialy. it can be done at 
more levels if needed; each OR-ing is a candidate for it.
Further tweaking can be made, including not using a union but doing 
several queries for the 1st-level alternatives (but losing overall 
order_by etc).
  - can i use query().join() to form the expression and stick it
 into the union somehow? should i take query.criterion or something 
else?
yes
q = query(A).whatever-joins-filters()
s = q._compile_context().statement 
use s for the union's elements. do not forget to add to each q all 
relevant joins and filters that have been taken outside the 
(or/and/or/..) parenthesis in the initial big query.
then, myunion = union( *allthese)

 - can then the union be put into the query of say root 
 object?
yes. use query(A).select_from( myunion)
other ways:
 - query(A).from_statement( myunion) works but does not allow further 
joins/filters. Although the union is just different As, it will not 
be treated as such.
 - one can make a secondary mapper if the query structure is static:
   m = sa.mapper( A, table=myunion, non_primary=True )
   r = session.query( m).whatever ...

btw this is going towards query arithmetics that i've been talking 
since long time. i hope one day things like this will be in SA as a 
sort of 3rd layer over sql and plain orm. 

ciao
svilen
www.svilendobrev.com / dbcook.sf.net

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] InnoDB - Foreign Key must be an Index

2008-10-01 Thread GustaV

Hi all,

I'm experiencing an issue on MySQL (5.0.51a) when sqlalchemy create
the tables with foreign keys.

The SQL issued :
CREATE TABLE `referenced` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY
) TYPE = InnoDB;

CREATE TABLE `referencing` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`f` INT NOT NULL,
FOREIGN KEY(f) REFERENCES referenced(id)
) TYPE = InnoDB;

I got an error (#1005 - Can't create table './seed-online/
referencing.frm' (errno: 150) )... I solve this when I specify
explicitly the foreign key being an index (looks like it is the
normal way to do this)

CREATE TABLE `referencing` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`f` INT NOT NULL,
INDEX(f),
FOREIGN KEY(f) REFERENCES referenced(id)
) TYPE = InnoDB;

But I don't know how to tell sqlalchemy to explicitely set that index.
On the other hand, at home (using wampserver2.0c, same version of
MySQL) it works : it looks like the index is set automatically if not
already set (I red this in the MySQL docs).

So I'm looking for either :
- an option to tell sqlalchemy to set the index explicitely
- or, the option in MySQL to turn 'on' to have this INDEX
automatically!

Thanks a lot!

Guillaume

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Instance added to session and flushed by backref before save() is actually called

2008-10-01 Thread Michael Bayer


On Oct 1, 2008, at 6:42 AM, Adam Dziendziel wrote:


 I have a ContentObject class mapped using:

 co_mapper = orm.mapper(ContentObject,
   content_objects_table,
   extension=COMapperExtension(),
   polymorphic_on=content_objects_table.c.type,
   polymorphic_identity='ContentObject',
   properties={
'theme': orm.relation(Theme),
'resources': orm.relation(Resource,
  secondary=co_resources_table),
'children': orm.relation(ContentObject,
secondary=co_children_table,

 primaryjoin=content_objects_table.c.id==co_children_table.c.parent_id,

 secondaryjoin
 =co_children_table.c.child_id==content_objects_table.c.id,
backref='parents'),
'translations': orm.relation(ContentObjectTranslation,
 backref='co')
   }
 )

 co = ContentObject()
 co.children.append(Session.query(ContentObject).get(1))
 # assert co not in Session # fails!
 co.theme = Session.query(Theme).get(1) # Session flushes automatically
 when retrieving a theme, and I get an error because the  theme_id
 column (with nullable=False) is not set yet

 IntegrityError: (IntegrityError) content_objects.theme_id may not be
 NULL u'INSERT INTO content_objects (type, parent_id, position,
 theme_id, data, keywords) VALUES (?, ?, ?, ?, ?, ?)' ['group', None,
 None, None, None, '']

 If I remove backref='parents' it works as expected. Do I have to turn
 auto-flush off to avoid incidental flushes?

If you're on 0.5, you can in fact disable save-update cascade on the  
backref, and it should work as planned, using  
backref=backref('parent', cascade=None).

Though lately I've just been using a @disable_autoflush decorator for  
this situation, in a web app typically there's one controller method  
that does the populate operation so that works out OK.





--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Uppercase column names in table.insert({ })

2008-10-01 Thread Gaetan de Menten

On Mon, Sep 29, 2008 at 4:46 PM, Itamar Ravid [EMAIL PROTECTED] wrote:
 Thanks for the answer, Mike. I was used to Oracle's behavior while writing
 raw SQL, in which the case of unquoted column identifiers doesn't matter.
 This behavior seems reasonable enough, although the inconsistency between
 the cursor description and SQLA's column identifiers could throw some people
 off.

 This causes the versioned plugin from Elixir.ext to fail on Oracle, so I'll
 submit a patch against it to lowercase column names in table.insert()'s.
 Thanks again.

I can't accept this patch as it breaks for people using non-lowercase
column names on non-Oracle database.
See http://elixir.ematia.de/trac/ticket/73

Some comments:
- it fails silently: Mike, is it expected that when you do:
connection.execute(table.insert(), {inexistant_field: somevalue}),
it doesn't complain in any way?
- I really think this should be fixed at SA-level (probably in the
reflection code), as we don't do anything fancy in there...

Here is roughly what happens:

my_table = Table(my_table, metadata, autoload=True)
my_table2 = Table(my_table2, metadata, *[col.copy() for col in my_table.c])
metadata.create_all()

values = my_table.select().execute().fetchone()
connection.execute(my_table2.insert(), values)

 On Mon, Sep 29, 2008 at 5:39 PM, Michael Bayer [EMAIL PROTECTED]
 wrote:



 This is the expected behavior.  SQLA operates in a case sensitive
 fashion whenever a table or column identifier is given in mixed case
 or upper case.   Use all lower case for case insensitive.  Since
 SQLA seeks to provide a database-agnostic API to the backend, this
 includes Oracle as well.case sensitive means that the identifier
 will be quoted, in which case the database expects to match the
 identifier against an identifier of the exact same characters.
 Oracle's usual UPPERCASE identifiers are in fact case insensitive.
 So for case insensitive identifiers, make sure you use all lower case
 names like 'book_id'.

 The keys() method of the ResultProxy, OTOH, doesn't attempt to
 editorialize what comes back from the cursor, so in the case of oracle
 you get upper case names (these are acceptable to use as keys for
 row['somekey']).   While we maybe could try to connect the original
 select() statement's SQLA-encoded column names back to the
 cursor.description's keys and return them as defined on the SQLAlchemy
 side, you'd still get the uppercase names when we didn't have that
 information, like execute(select * from table).   I have a vague
 recollection of someone having a specific issue with that behavior but
 I'm not finding what it was at the moment.


 On Sep 29, 2008, at 10:04 AM, Itamar Ravid wrote:

 
  Hey guys - I've ran into a strange bug in 0.4.7p1 while trying to make
  use of Elixir's versioned plugin. In Oracle, given a table created as
  such:
 
  CREATE TABLE books
  (book_id NUMBER PRIMARY KEY);
 
  The following code fails:
 
  dbEng = create_engine(oracle://:@pearl)
  meta = MetaData()
  meta.bind = dbEng
 
  booksTable = Table(books, meta, autoload=True)
 
  booksTable.insert({'BOOK_ID': 200}).execute()
 
  Whilst the following, succeeds:
 
  booksTable.insert({'book_id': 200}).execute()
 
  This is strange, considering the fact that the following:
 
  result = booksTable.select().execute().fetchone()
  print result.keys()
 
  ... results in the column names in uppercase.
 
  Am I doing anything wrong?
 



-- 
Gaëtan de Menten
http://openhex.org

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] OrderingList and list.sort()

2008-10-01 Thread Adam Dziendziel

Hi,

It seems that sorting of ordering list doesn't work. Attribute
object.items is an OrderingList:

object.items.sort(cmp=my_cmp)

The list is sorted, but the ordering column is not updated. I need to
call explicitly:

object.items._reorder()

Maybe override sort() in OrderingList to invoke self._reorder() after
sorting?


Thanks,
Adam
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Instance added to session and flushed by backref before save() is actually called

2008-10-01 Thread Adam Dziendziel

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: InnoDB - Foreign Key must be an Index

2008-10-01 Thread GustaV

Actually, like I said, I tried it on my local config and it worked ok
as well! That's why I suspect some MySQL configuration issue but...
The only thing I have noticed is the default table format :
- InnoDB at home, it works
- MyISAM on the server, it fails (it creates InnoDB tables because I
ask him to do it in sqlalchemy)
But I don't really see why it would fail.

Posting my sqlalchemy code wouldn't be helpful (and it would be a
mess! :) ) because it is really a MySQL error... :(

On Oct 1, 3:27 pm, Alex K [EMAIL PROTECTED] wrote:
 Hi Guillaume,

 The issue that you've faced looks strange - I've just tried to execute
 your first example causing the error on my 5.0.45 mysql server and
 tables were created ok. Can you post the code snippet causing the
 error?

 Regards,
 Alex

 On 1 окт, 16:59, GustaV [EMAIL PROTECTED] wrote:

  Hi all,

  I'm experiencing an issue on MySQL (5.0.51a) when sqlalchemy create
  the tables with foreign keys.

  The SQL issued :
  CREATE TABLE `referenced` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY
  ) TYPE = InnoDB;

  CREATE TABLE `referencing` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  `f` INT NOT NULL,
  FOREIGN KEY(f) REFERENCES referenced(id)
  ) TYPE = InnoDB;

  I got an error (#1005 - Can't create table './seed-online/
  referencing.frm' (errno: 150) )... I solve this when I specify
  explicitly the foreign key being an index (looks like it is the
  normal way to do this)

  CREATE TABLE `referencing` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  `f` INT NOT NULL,
  INDEX(f),
  FOREIGN KEY(f) REFERENCES referenced(id)
  ) TYPE = InnoDB;

  But I don't know how to tell sqlalchemy to explicitely set that index.
  On the other hand, at home (using wampserver2.0c, same version of
  MySQL) it works : it looks like the index is set automatically if not
  already set (I red this in the MySQL docs).

  So I'm looking for either :
  - an option to tell sqlalchemy to set the index explicitely
  - or, the option in MySQL to turn 'on' to have this INDEX
  automatically!

  Thanks a lot!

  Guillaume
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Uppercase column names in table.insert({ })

2008-10-01 Thread Michael Bayer


On Oct 1, 2008, at 10:03 AM, Gaetan de Menten wrote:


 On Mon, Sep 29, 2008 at 4:46 PM, Itamar Ravid  
 [EMAIL PROTECTED] wrote:
 Thanks for the answer, Mike. I was used to Oracle's behavior while  
 writing
 raw SQL, in which the case of unquoted column identifiers doesn't  
 matter.
 This behavior seems reasonable enough, although the inconsistency  
 between
 the cursor description and SQLA's column identifiers could throw  
 some people
 off.

 This causes the versioned plugin from Elixir.ext to fail on Oracle,  
 so I'll
 submit a patch against it to lowercase column names in  
 table.insert()'s.
 Thanks again.

 I can't accept this patch as it breaks for people using non-lowercase
 column names on non-Oracle database.
 See http://elixir.ematia.de/trac/ticket/73

 Some comments:
 - it fails silently: Mike, is it expected that when you do:
 connection.execute(table.insert(), {inexistant_field: somevalue}),
 it doesn't complain in any way?

I think that is the current behavior, but it is not ideal.  It's  
likely that validating the incoming dict would add palpable overhead  
to SQL execution, but I haven't analyzed deeply.


 - I really think this should be fixed at SA-level (probably in the
 reflection code), as we don't do anything fancy in there...

 Here is roughly what happens:

 my_table = Table(my_table, metadata, autoload=True)
 my_table2 = Table(my_table2, metadata, *[col.copy() for col in  
 my_table.c])
 metadata.create_all()

im not sure about this one, oracle reflection definitely works.

 values = my_table.select().execute().fetchone()
 connection.execute(my_table2.insert(), values)

still somewhat controversial for the reasons I mentioned earlier,  
perhaps oracle's _normalize_name() should be applied to  
cursor.description.



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: enumeration values in the column - referenced from another table

2008-10-01 Thread az

maybe try, instead of hiding the conversion inside db-types layer, to 
move it upper, i.e. make it a real reference/FK-column to real 
object/table, then make a python property (see synonim) to do the 
conversion.

On Tuesday 30 September 2008 23:20:16 rca wrote:
 Hi all,

 my apologies for a long question, I am new to sqlalchemy and I was
 struggling with one problem. I solved it but I really not sure it's
 the right way to do it.

 The problem is that I need to create objects like this:
 Token(pos=2, surface=helloWorld)

 The surface is string, but in the database, it should be saved as
 reference to an other table (looked-up and saved if not existing)


 The way I solved it was to create my own column type decorating
 Integer. On the way in, it gets text and stores id, on the way out,
 it gives the text back.

 But I don't know if my solution is safe. For instance,
 -- I am decorating Integer type, but on the output there is string.
 -- I am using the EntitySingleton recipy, but I found out I could
 not use the recommended
 Session = scoped_session(sessionmaker())
 I had to say: Session = sessionmaker()
 -- And I do commit for every new looked-up value

 And also, I have the impression the solution is very complicated,
 perhaps you could help me to do it in a better way.

 Many thanks!

   roman

 Here is the code with an example:
 ---

 import sqlalchemy as sa
 from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.orm import scoped_session, sessionmaker, relation,
 backref, mapper
 from sqlalchemy import create_engine, Table, Column, Integer,
 String, MetaData, ForeignKey
 #from mimetypes import types_map
 import weakref
 import sqlalchemy.types as types


 Session = sessionmaker()  #scoped_session(sessionmaker)

 DBase = declarative_base()

 class MyUnique(types.TypeDecorator):
 a type that decorates Integer,
 receives a text representation - eg. MyValueFromEnumeration
 and replaces it in the database with id of the string above
 It makes sure that inserted values are unique (creates them if
 not exist)

 impl = types.Integer

 def process_bind_param(self, value, dialect):
 #ukladani do databaze
 if not hasattr(self, '__unique_valuee'):
 self.__unique_valuee = Surface(value)
 return self.__unique_valuee.id

 def process_result_value(self, value, dialect):
 #vystup
 return self.__unique_valuee.surface

  #if it is string type
 def copy(self):
 return MyUniqueString(self.impl.length)
 

 class DocumentBase(object):
 def __init__(self):
 self.metadata = DBase.metadata
 self.engine = None

 def open(self, url='sqlite:///:memory:'):
 self.engine = create_engine(url, echo=True)
 #engine = create_engine('sqlite:///' + __file__ + .db,
 echo=True)
 Session.configure(bind=self.engine)
 self.metadata.bind = self.engine


 surface_table = sa.Table('surface', self.metadata,
 sa.Column('id', sa.Integer, primary_key=True,
 autoincrement=True),
 sa.Column('surface', sa.String(500),
 autoincrement=True) )

 mapper(Surface, surface_table)

 self.metadata.create_all(checkfirst=True)

 def add(self, document_object):
 sess = Session()
 sess.save_or_update(document_object)
 sess.commit()



 class EntitySingleton(type):
 a metaclass that insures the creation of unique and non-
 existent entities for
 a particular constructor argument.  if an entity with a
 particular constructor
 argument was already created, either in memory or in the
 database, it is returned
 in place of constructing the new instance.

 def __init__(cls, surface, bases, dct):
 cls.instances = weakref.WeakValueDictionary()

 def __call__(cls, surface):
 session = Session()

 hashkey = surface
 try:
 return cls.instances[hashkey]
 except KeyError:
 instance =
 session.query(cls).filter(cls.surface==surface).first()
 if instance is None:
 instance = type.__call__(cls, surface)
 #session.begin_nested()
 session.add(instance)
 session.commit()
 # optional - flush the instance when it's saved
 session.flush([instance])
 cls.instances[hashkey] = instance
 return instance

 class Document(DBase):
 __tablename__ = 'documents'
 id = sa.Column(sa.Integer(9), primary_key=True,
 autoincrement=True)
 name = sa.Column(sa.String(500))
 uri = sa.Column(sa.String(500))
 processing_stage = sa.Column(sa.String(500))

 tokens = relation(Token, backref=Document)

 def __xinit__(self, name):
 self.name = name
 def __repr__(self):
 return %s('%s','%s') % (self.__class__, self.id,
 self.name)

 class Token(DBase):
 

[sqlalchemy] Re: Attribute extension in 0.5rc1

2008-10-01 Thread Brett

I'm using AttributeExtension for my project and it would greatly
simplify things if I could receive the events after the attributes are
set.  Is there any way this will make it into SqlAlchemy?

On Sep 28, 8:09 pm, Mike Bernson [EMAIL PROTECTED] wrote:
 Michael Bayer wrote:

  On Sep 28, 2008, at 8:23 PM, Mike Bernson wrote:

  The set method has changed from 0.5b3 to 0.5rc1.

  The old set method set the value before it called the set method
  in attribute extension. The new method set the value after the
  set method is called.

  This is cause me problems because the methods that I am dispatching
  to think the attribute is set. Is it safe in the set method of the
  attribute method to set the attribute value by doing a follow:

  class ReceiveEvents(AttributeExtension):

      def set(self, obj, child, oldchild, initiator):
          key = initiator.key
          obj.dict[key] = child

          if child != oldchild:
              instance = obj.obj.__call__()
              instance.notify(model=instance, property=key,  
  old=oldchild, new=newchild)

          return obj.dict[key]

  instance.notify dispatch to methods that have register that they need
  to known about property changing value. The methods that get dispatch
  then can modify the property.

  oh yeah.   I think I meant to let you know about this (you're the only  
  person usingAttributeExtension) but i probably forgot :) .   The  
  change is necessary so that the extension can raise errors or modify  
  the value before its actually set.

  whats the question, you want to populate dict directly ?   Should be  
  fine for scalar attributes since thats what happens right after the  
  event anyway.

 Are there any other attribute type that might cause a problem ?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Attribute extension in 0.5rc1

2008-10-01 Thread Michael Bayer


On Oct 1, 2008, at 3:28 PM, Brett wrote:


 I'm using AttributeExtension for my project and it would greatly
 simplify things if I could receive the events after the attributes are
 set.  Is there any way this will make it into SqlAlchemy?

having the events received before is a strong feature since it allows  
you to validate and modify, or reject, the value before going in.
Having a whole new event issued afterwards would add overhead to all  
attribute operations unless we do some of the tricks that we do with  
MapperExtension to determine ahead of time if methods are actually  
present and don't call empty methods otherwise.

If your use case is limited to scalars and not collections, feel free  
to populate.   This is just saying state[key] = value, based on the  
incoming state and value.

The whole AttributeExtension as a public API is a brand new feature,  
so I'd be curious what your usage of it is.  I wonder if there might  
be alternatives for your particular use case.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] dictionary size changing on 0.5b3?

2008-10-01 Thread arashf

not sure if this is a known issue. but I thought it'd post it just in
case :)

Traceback (most recent call last):
File /srv/server/metaserver/metaserver/lib/base.py, line 48, in
__call__
ret = WSGIController.__call__(self, environ, start_response)
File /usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/pylons/
controllers/core.py, line 195, in __call__
after = self._inspect_call(self.__after__)
File /usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/pylons/
controllers/core.py, line 79, in _inspect_call
result = func(**args)
File /srv/server/metaserver/metaserver/lib/base.py, line 86, in
__after__
metaserver.model.Session.commit()
File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/
sqlalchemy/orm/scoping.py, line 106, in do
return getattr(self.registry(), name)(*args, **kwargs)
File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/
sqlalchemy/orm/session.py, line 663, in commit
self.transaction.commit()
File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/
sqlalchemy/orm/session.py, line 376, in commit
self._prepare_impl()
File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/
sqlalchemy/orm/session.py, line 360, in _prepare_impl
self.session.flush()
File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/
sqlalchemy/orm/session.py, line 1346, in flush
if (not self.identity_map.check_modified() and
File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/
sqlalchemy/orm/identity.py, line 44, in check_modified
for state in self._mutable_attrs:
File /usr/lib/python2.5/weakref.py, line 303, in iterkeys
for wr in self.data.iterkeys():
RuntimeError: dictionary changed size during iteration

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: dictionary size changing on 0.5b3?

2008-10-01 Thread Michael Bayer

its not.  multiple threads hitting your Session there ?   otherwise  
might be an async gc.collect() causing that.


On Oct 1, 2008, at 9:25 PM, arashf wrote:


 not sure if this is a known issue. but I thought it'd post it just in
 case :)

 Traceback (most recent call last):
 File /srv/server/metaserver/metaserver/lib/base.py, line 48, in
 __call__
 ret = WSGIController.__call__(self, environ, start_response)
 File /usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/ 
 pylons/
 controllers/core.py, line 195, in __call__
 after = self._inspect_call(self.__after__)
 File /usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/ 
 pylons/
 controllers/core.py, line 79, in _inspect_call
 result = func(**args)
 File /srv/server/metaserver/metaserver/lib/base.py, line 86, in
 __after__
 metaserver.model.Session.commit()
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3- 
 py2.5.egg/
 sqlalchemy/orm/scoping.py, line 106, in do
 return getattr(self.registry(), name)(*args, **kwargs)
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3- 
 py2.5.egg/
 sqlalchemy/orm/session.py, line 663, in commit
 self.transaction.commit()
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3- 
 py2.5.egg/
 sqlalchemy/orm/session.py, line 376, in commit
 self._prepare_impl()
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3- 
 py2.5.egg/
 sqlalchemy/orm/session.py, line 360, in _prepare_impl
 self.session.flush()
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3- 
 py2.5.egg/
 sqlalchemy/orm/session.py, line 1346, in flush
 if (not self.identity_map.check_modified() and
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3- 
 py2.5.egg/
 sqlalchemy/orm/identity.py, line 44, in check_modified
 for state in self._mutable_attrs:
 File /usr/lib/python2.5/weakref.py, line 303, in iterkeys
 for wr in self.data.iterkeys():
 RuntimeError: dictionary changed size during iteration

 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: dictionary size changing on 0.5b3?

2008-10-01 Thread jilong

I do not know is the cause of the problem.The availability of source code?

2008/10/2 arashf [EMAIL PROTECTED]:

 not sure if this is a known issue. but I thought it'd post it just in
 case :)

 Traceback (most recent call last):
 File /srv/server/metaserver/metaserver/lib/base.py, line 48, in
 __call__
 ret = WSGIController.__call__(self, environ, start_response)
 File /usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/pylons/
 controllers/core.py, line 195, in __call__
 after = self._inspect_call(self.__after__)
 File /usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/pylons/
 controllers/core.py, line 79, in _inspect_call
 result = func(**args)
 File /srv/server/metaserver/metaserver/lib/base.py, line 86, in
 __after__
 metaserver.model.Session.commit()
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/
 sqlalchemy/orm/scoping.py, line 106, in do
 return getattr(self.registry(), name)(*args, **kwargs)
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/
 sqlalchemy/orm/session.py, line 663, in commit
 self.transaction.commit()
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/
 sqlalchemy/orm/session.py, line 376, in commit
 self._prepare_impl()
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/
 sqlalchemy/orm/session.py, line 360, in _prepare_impl
 self.session.flush()
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/
 sqlalchemy/orm/session.py, line 1346, in flush
 if (not self.identity_map.check_modified() and
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3-py2.5.egg/
 sqlalchemy/orm/identity.py, line 44, in check_modified
 for state in self._mutable_attrs:
 File /usr/lib/python2.5/weakref.py, line 303, in iterkeys
 for wr in self.data.iterkeys():
 RuntimeError: dictionary changed size during iteration

 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: dictionary size changing on 0.5b3?

2008-10-01 Thread Michael Bayer

theres a fix in r5137 which resolves this.


On Oct 1, 2008, at 9:25 PM, arashf wrote:


 not sure if this is a known issue. but I thought it'd post it just in
 case :)

 Traceback (most recent call last):
 File /srv/server/metaserver/metaserver/lib/base.py, line 48, in
 __call__
 ret = WSGIController.__call__(self, environ, start_response)
 File /usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/ 
 pylons/
 controllers/core.py, line 195, in __call__
 after = self._inspect_call(self.__after__)
 File /usr/lib/python2.5/site-packages/Pylons-0.9.6.2-py2.5.egg/ 
 pylons/
 controllers/core.py, line 79, in _inspect_call
 result = func(**args)
 File /srv/server/metaserver/metaserver/lib/base.py, line 86, in
 __after__
 metaserver.model.Session.commit()
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3- 
 py2.5.egg/
 sqlalchemy/orm/scoping.py, line 106, in do
 return getattr(self.registry(), name)(*args, **kwargs)
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3- 
 py2.5.egg/
 sqlalchemy/orm/session.py, line 663, in commit
 self.transaction.commit()
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3- 
 py2.5.egg/
 sqlalchemy/orm/session.py, line 376, in commit
 self._prepare_impl()
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3- 
 py2.5.egg/
 sqlalchemy/orm/session.py, line 360, in _prepare_impl
 self.session.flush()
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3- 
 py2.5.egg/
 sqlalchemy/orm/session.py, line 1346, in flush
 if (not self.identity_map.check_modified() and
 File /usr/lib/python2.5/site-packages/SQLAlchemy-0.5.0beta3- 
 py2.5.egg/
 sqlalchemy/orm/identity.py, line 44, in check_modified
 for state in self._mutable_attrs:
 File /usr/lib/python2.5/weakref.py, line 303, in iterkeys
 for wr in self.data.iterkeys():
 RuntimeError: dictionary changed size during iteration

 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---