Re: [sqlalchemy] Re: SQLAlchemy Tables Definitoons as soaplib Complex Types, help!

2010-04-06 Thread Kapil Thangavelu
your probably better off creating a parallel hierarchy for soap
serialization and then adapting the sqlalchemy types to/from it as needed.

if you want to do the metaclass thing, you'll probably need to overide call
in your synthentic metaclass and call both the base meta classes call
methods.

cheers,

-kapil


On Tue, Apr 6, 2010 at 2:37 AM, snf lukasz.cz...@gmail.com wrote:

 anyone have an idea? this prevents me from developing further.

 Thank you in advance.

 On Apr 1, 1:33 pm, snf lukasz.cz...@gmail.com wrote:
  Hi,
 
  I'm trying to implement a soap interface that will allow me to pass
  pure sqlalchemy objects as a reponse. I'm using the declarative based
  table definition and a soaplib library to do that. The project is a
  pylons project.
 
  The problem is that when i do:
 
  from project.model.meta import Base # declarative base
  from soaplib.serializers.clazz import ClassSerializer
  from soaplib.serializers.primitive import Integer
 
  quote
  class Resource(Base, ClassSerializer):
 
  # ...field definitions follow...
 
  # then i define soap types of the fields
  class types:
  id = Integer
  subid  = Integer
 
  /quote
 
  I had a problem with multiple __metaclass__ definitions, which i
  overcame with this snippet:
 
  http://code.activestate.com/recipes/204197-solving-the-metaclass-conf...
 
  so I added:
 
  __metaclass__ = classmaker()
 
  after:
 
  class Resource(Base, ClassSerializer):
 
  and the problem was solved. But now in my controller, when I try to
  return this object:
 
  quote
  @soap_method(soap_str, _returns = Resource)
  def get(self, name):
  agent =
  db_session.query(Resource).filter(Resource.name==name).first()
  return agent
  /quote
 
  I get an error:
 
  type object 'Resource' has no attribute 'soap_members'
 
  which is set by the soaplib's ClassSerializer's __metaclass__ in
  theory (I looked through the code). So it seems that the multiple
  __metaclass__ hack (mentioned above) is not firing the __call__ method
  of ClassSerializer's __metaclass__
 
  Does any one have any idea how to overcome that? Is it even possible?

 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@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 sqlalch...@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] orm overrides explicit value sets

2007-12-04 Thread Kapil Thangavelu
i've attached an example, where a class constructor setups a default value
on a relation field, in the constructor, the app code latter explicitly sets
the fk attribute on the class, but sa ignores this value, and in the
flushing process sets it be the value of the orm field, so that it
'magically' becomes none even though it was explicitly set, which throws an
integrity constraint violation since the fk is setup to be not null.
not sure if this a bug or just a warning on sa usage patterns..

cheers,

kapil

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

from sqlalchemy import create_engine, MetaData, Table, Column, types, ForeignKey
from sqlalchemy.orm import mapper, session, relation

metadata = MetaData()
metadata.bind = create_engine('sqlite://')

model_table = Table(models,
metadata,
Column(id, types.Integer, primary_key=True),
Column(status_id, types.Integer, ForeignKey(statuses.id), nullable=False),
)

status_table = Table(statuses,
 metadata,
 Column(id, types.Integer, primary_key=True),
 Column(name, types.Unicode, unique=True )
 )

metadata.create_all()

class Model( object ):

def __init__( self, status=None):
self.status = None

class Status( object ): pass

mapper( Model, model_table,
properties = {
   'status': relation( Status, backref=models)
   }
)

mapper( Status, status_table )

status_table.insert( values=dict(id=1, name=u'production') ).execute()

s = session.Session()

m = Model()
m.status_id = 1

s.save(m)
# nice error .. integrity constraint violation,  message status_id is null magically
s.flush()
















[sqlalchemy] odd adjancency list w/ join_depth behavior

2007-11-29 Thread Kapil Thangavelu
hi folks,
i seem to be running into a bug or misconfiguration with sqlalchemy's tree
handling.. the table and mapping themselves seem fairly innocuous

concepts_table = Table(concepts, metadata,
   Column(id, types.Integer, primary_key=True),
   Column(name, types.Unicode, nullable=True),
   Column(parent, types.Integer, ForeignKey(
concepts.id) )
   )

class Concept( object ): pass

mapper(Concept, concepts_table, properties={
'children': relation(Concept, cascade=all,
 backref=backref(parent_node,
remote_side=[concepts_table.c.id]),

collection_class=attribute_mapped_collection('name'),
 lazy=False, join_depth=3)})

the odd part is if i specify any join_depth i got an error, if i leave it
off its fine. i'm still curious to find out what causes the error and if its
a bug or just misconfiguration on my part.

i'm attaching a script which demonstrates the issue, and a contextual
traceback (ipython) of the error.


thanks,

kapil

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

110 
111 s = session.Session()
-- 112 for i in s.query( Concept ).all():
113 print i.name
114 

/Users/kapil/projects/piston/src/sqlalchemy/lib/sqlalchemy/orm/query.py in 
all(self)
606 This results in an execution of the underlying query.
607 
-- 608 return list(self)
609 
610 

/Users/kapil/projects/piston/src/sqlalchemy/lib/sqlalchemy/orm/query.py in 
__iter__(self)
654 if self._autoflush and not self._populate_existing:
655 self.session._autoflush()
-- 656 return self._execute_and_instances(context)
657 
658 def _execute_and_instances(self, querycontext):

/Users/kapil/projects/piston/src/sqlalchemy/lib/sqlalchemy/orm/query.py in 
_execute_and_instances(self, querycontext)
659 result = self.session.execute(querycontext.statement, 
params=self._params, mapper=self.mapper, instance=self._refresh_instance)
660 try:
-- 661 return iter(self.instances(result, 
querycontext=querycontext))
662 finally:
663 result.close()

/Users/kapil/projects/piston/src/sqlalchemy/lib/sqlalchemy/orm/query.py in 
instances(self, cursor, *mappers_or_columns, **kwargs)
720 self.select_mapper._instance(context, 
self._primary_adapter(row), result, **primary_mapper_args)
721 else:
-- 722 self.select_mapper._instance(context, row, result, 
**primary_mapper_args)
723 for proc in process:
724 proc[0](context, row)

/Users/kapil/projects/piston/src/sqlalchemy/lib/sqlalchemy/orm/mapper.py in 
_instance(self, context, row, result, skip_polymorphic, extension, 
only_load_props, refresh_instance)
   1453 flags = {'instancekey':identitykey, 'isnew':isnew}
   1454 if 'populate_instance' not in extension.methods or 
extension.populate_instance(self, context, row, instance, 
only_load_props=only_load_props, **flags) is EXT_CONTINUE:
- 1455 self.populate_instance(context, instance, row, 
only_load_props=only_load_props, **flags)
   1456 if 'append_result' not in extension.methods or 
extension.append_result(self, context, row, instance, result, **flags) is 
EXT_CONTINUE:
   1457 if result is not None:

/Users/kapil/projects/piston/src/sqlalchemy/lib/sqlalchemy/orm/mapper.py in 
populate_instance(self, selectcontext, instance, row, ispostselect, isnew, 
only_load_props, **flags)
   1541 
   1542 for (key, populator) in populators:
- 1543 selectcontext.exec_with_path(self, key, populator, 
instance, row, ispostselect=ispostselect, isnew=isnew, **flags)
   1544 
   1545 if self.non_primary:

/Users/kapil/projects/piston/src/sqlalchemy/lib/sqlalchemy/orm/query.py in 
exec_with_path(self, mapper, propkey, func, *args, **kwargs)
   1235 self.path += (mapper.base_mapper, propkey)
   1236 try:
- 1237 return func(*args, **kwargs)
   1238 finally:
   1239 self.path = oldpath

/Users/kapil/projects/piston/src/sqlalchemy/lib/sqlalchemy/orm/strategies.py in 
execute(instance, row, isnew, **flags)
605 self.logger.debug(eagerload list instance on 
%s % mapperutil.attribute_str(instance, self.key))
606 
-- 607 self.select_mapper._instance(selectcontext, 
decorated_row, result_list)
608 
609 


[sqlalchemy] introspecting backreferences

2007-11-05 Thread Kapil Thangavelu
i've got two mapped classes in a many 2 many relationship. i declare the
relationship on one class mapper with a backreference attribute specified.
i'm interested to know if i can find this backreference property from the
other class in the relationship which doesn't have the mapper property
specified ( ie. other side of the m2m relationship ). i poked at the mapper
and the class, i can see the back references as instrumented properties on
the class, but the mapper itself doesnt publicly expose them through its
properties attribute, it maintains a private (__props) mapping. is there any
public api for looking at the backreferences to to a class?

cheers,

kapil

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