Re: [sqlalchemy] How to correctly merge objects of type X or any subclass of type X into the session?

2016-02-16 Thread Michael Naber
That's interesting. So, if I'm trying to move instances between threads, is
it recommended that I pass between threads the instance id, and then in the
receiving thread use session.query(Person).get(instance_id), or... should I
pass the instance itself (not by ID), and then use session.merge(instance)?

My objective is that I would want to have full access to access and modify
the instance in the session of the receiving thread.

Thank you,
Michael

On Tue, Feb 16, 2016 at 11:26 AM, Mike Bayer <clas...@zzzcomputing.com>
wrote:

> answered
>
>
>
> On 02/16/2016 09:08 AM, Michael Naber wrote:
>
>> I would like to write code which can correctly merge objects of type X
>> or any subclass of type X into the session. I have been doing
>> session.merge(X(id=??)), which works fine for merging type X, but if the
>> object ID references an instance of any subclass of X, the merge results
>> in the discriminator being set incorrectly. Code example here:
>> http://stackoverflow.com/questions/35414057
>>
>> Any help much appreciated.
>>
>> Regards,
>> Michael
>>
>> --
>> 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
>> <mailto:sqlalchemy+unsubscr...@googlegroups.com>.
>> To post to this group, send email to sqlalchemy@googlegroups.com
>> <mailto:sqlalchemy@googlegroups.com>.
>> Visit this group at https://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 https://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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] How to correctly merge objects of type X or any subclass of type X into the session?

2016-02-16 Thread Michael Naber
I would like to write code which can correctly merge objects of type X or
any subclass of type X into the session. I have been doing
session.merge(X(id=??)), which works fine for merging type X, but if the
object ID references an instance of any subclass of X, the merge results in
the discriminator being set incorrectly. Code example here:
http://stackoverflow.com/questions/35414057

Any help much appreciated.

Regards,
Michael

-- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] SQLAlchemy under Jython fails with Maximum Recursion Depth Exceeded

2015-10-06 Thread Michael Naber
Hopefully this should be pretty straightforward. I'm running the following
example which fails under Jython 2.7.0 with postgresql-9.4-1203.jdbc42.jar
using sqlalchemy 1.0.8 with PostgreSQL 9.3.9 on Ubuntu 14.04. Any help
would be much appreciated.


Example and stack trace below:


from sqlalchemy import create_engine, ForeignKey
from sqlalchemy.orm import sessionmaker, scoped_session, relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column
from sqlalchemy.types import Integer, String, Float

Session = scoped_session(sessionmaker())
Base = declarative_base()

class Address(Base):
__tablename__ = 'address'
id = Column(Integer, primary_key=True)
email_address = Column(String, nullable=False)
person_id = Column(Integer, ForeignKey('person.id'))


class Person(Base):
__tablename__ = 'person'
id = Column(Integer, primary_key=True)
_rate = Column(Float)
name = Column(String, nullable=False)
addresses = relationship("Address", order_by="Address.id", backref="person")

engine = 
create_engine('postgresql+zxjdbc://michael:test123@localhost:5432/ajtest',
echo=True)
#engine = create_engine('postgresql://michael:test123@localhost:5432/ajtest',
echo=True)
Session.configure(bind=engine)
Base.metadata.bind = engine

Base.metadata.drop_all(checkfirst=True)
Base.metadata.create_all()

s = Session()
mickeybob = Person(name='Michael')

s.add(mickeybob)
s.add(Address(email_address='t...@example.com',
 person=mickeybob))

s.commit()


for a in s.query(Address).all():
print a.email_address, a.person.name



--

Here is the error I get when running under Jython:





$ jython test_sqla.py
2015-10-06 15:32:58,750 INFO sqlalchemy.engine.base.Engine select
current_schema()
2015-10-06 15:32:58,753 INFO sqlalchemy.engine.base.Engine ()
2015-10-06 15:32:58,808 INFO sqlalchemy.engine.base.Engine SELECT
CAST('test plain returns' AS VARCHAR(60)) AS anon_1
2015-10-06 15:32:58,813 INFO sqlalchemy.engine.base.Engine ()
2015-10-06 15:32:58,816 INFO sqlalchemy.engine.base.Engine SELECT
CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
2015-10-06 15:32:58,819 INFO sqlalchemy.engine.base.Engine ()
2015-10-06 15:32:58,821 INFO sqlalchemy.engine.base.Engine show
standard_conforming_strings
2015-10-06 15:32:58,822 INFO sqlalchemy.engine.base.Engine ()
2015-10-06 15:32:58,835 INFO sqlalchemy.engine.base.Engine select relname
from pg_class c join pg_namespace n on n.oid=c.relnamespace where
pg_catalog.pg_table_is_visible(c.oid) and relname=?
2015-10-06 15:32:58,845 INFO sqlalchemy.engine.base.Engine (u'address',)
2015-10-06 15:32:58,865 INFO sqlalchemy.engine.base.Engine select relname
from pg_class c join pg_namespace n on n.oid=c.relnamespace where
pg_catalog.pg_table_is_visible(c.oid) and relname=?
2015-10-06 15:32:58,874 INFO sqlalchemy.engine.base.Engine (u'person',)
Traceback (most recent call last):
  File "test_sqla.py", line 29, in 
Base.metadata.drop_all(checkfirst=True)
  File
"/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/sql/schema.py",
line 3711, in drop_all
bind._run_visitor(ddl.SchemaDropper,
  File
"/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/engine/base.py",
line 1856, in _run_visitor
conn._run_visitor(visitorcallable, element, **kwargs)
  File
"/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/engine/base.py",
line 1480, in _run_visitor
visitorcallable(self.dialect, self,
  File
"/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/sql/visitors.py",
line 121, in traverse_single
return meth(obj, **kw)
  File "/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/sql/ddl.py",
line 813, in visit_metadata
filter_fn=lambda constraint: False
  File "/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/sql/ddl.py",
line 813, in visit_metadata
filter_fn=lambda constraint: False
  File "/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/sql/ddl.py",
line 1067, in sort_tables_and_constraints
candidate_sort = list(
  File "/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/sql/ddl.py",
line 1067, in sort_tables_and_constraints
candidate_sort = list(
  File
"/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/util/topological.py",
line 50, in sort
for set_ in sort_as_subsets(tuples, allitems, deterministic_order):
  File
"/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/util/topological.py",
line 39, in sort_as_subsets
todo.difference_update(output)
  File
"/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/util/_collections.py",
line 458, in difference_update
set.difference_update(self, other)
  File
"/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/util/_collections.py",
line 458, in difference_update
set.difference_update(self, other)

[removed repeated recursive calls]

  File
"/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/util/_collections.py",
line 458, in difference_update
set.difference_update(self, other)
RuntimeError: maximum recursion depth exceeded (Java 

[sqlalchemy] Re: SQLAlchemy under Jython fails with Maximum Recursion Depth Exceeded

2015-10-06 Thread Michael Naber
It could be due to this:
http://sourceforge.net/p/jython/mailman/message/34131065/

On Tue, Oct 6, 2015 at 11:35 AM, Michael Naber <mickey...@gmail.com> wrote:

> Hopefully this should be pretty straightforward. I'm running the following
> example which fails under Jython 2.7.0 with postgresql-9.4-1203.jdbc42.jar
> using sqlalchemy 1.0.8 with PostgreSQL 9.3.9 on Ubuntu 14.04. Any help
> would be much appreciated.
>
>
> Example and stack trace below:
>
>
> from sqlalchemy import create_engine, ForeignKey
> from sqlalchemy.orm import sessionmaker, scoped_session, relationship
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy import Column
> from sqlalchemy.types import Integer, String, Float
>
> Session = scoped_session(sessionmaker())
> Base = declarative_base()
>
> class Address(Base):
> __tablename__ = 'address'
> id = Column(Integer, primary_key=True)
> email_address = Column(String, nullable=False)
> person_id = Column(Integer, ForeignKey('person.id'))
>
>
> class Person(Base):
> __tablename__ = 'person'
> id = Column(Integer, primary_key=True)
> _rate = Column(Float)
> name = Column(String, nullable=False)
> addresses = relationship("Address", order_by="Address.id",
> backref="person")
>
> engine = 
> create_engine('postgresql+zxjdbc://michael:test123@localhost:5432/ajtest',
> echo=True)
> #engine = create_engine('postgresql://michael:test123@localhost:5432/ajtest',
> echo=True)
> Session.configure(bind=engine)
> Base.metadata.bind = engine
>
> Base.metadata.drop_all(checkfirst=True)
> Base.metadata.create_all()
>
> s = Session()
> mickeybob = Person(name='Michael')
>
> s.add(mickeybob)
> s.add(Address(email_address='t...@example.com',
>  person=mickeybob))
>
> s.commit()
>
>
> for a in s.query(Address).all():
> print a.email_address, a.person.name
>
>
>
> --
>
> Here is the error I get when running under Jython:
>
>
>
>
>
> $ jython test_sqla.py
> 2015-10-06 15:32:58,750 INFO sqlalchemy.engine.base.Engine select
> current_schema()
> 2015-10-06 15:32:58,753 INFO sqlalchemy.engine.base.Engine ()
> 2015-10-06 15:32:58,808 INFO sqlalchemy.engine.base.Engine SELECT
> CAST('test plain returns' AS VARCHAR(60)) AS anon_1
> 2015-10-06 15:32:58,813 INFO sqlalchemy.engine.base.Engine ()
> 2015-10-06 15:32:58,816 INFO sqlalchemy.engine.base.Engine SELECT
> CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
> 2015-10-06 15:32:58,819 INFO sqlalchemy.engine.base.Engine ()
> 2015-10-06 15:32:58,821 INFO sqlalchemy.engine.base.Engine show
> standard_conforming_strings
> 2015-10-06 15:32:58,822 INFO sqlalchemy.engine.base.Engine ()
> 2015-10-06 15:32:58,835 INFO sqlalchemy.engine.base.Engine select relname
> from pg_class c join pg_namespace n on n.oid=c.relnamespace where
> pg_catalog.pg_table_is_visible(c.oid) and relname=?
> 2015-10-06 15:32:58,845 INFO sqlalchemy.engine.base.Engine (u'address',)
> 2015-10-06 15:32:58,865 INFO sqlalchemy.engine.base.Engine select relname
> from pg_class c join pg_namespace n on n.oid=c.relnamespace where
> pg_catalog.pg_table_is_visible(c.oid) and relname=?
> 2015-10-06 15:32:58,874 INFO sqlalchemy.engine.base.Engine (u'person',)
> Traceback (most recent call last):
>   File "test_sqla.py", line 29, in 
> Base.metadata.drop_all(checkfirst=True)
>   File
> "/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/sql/schema.py",
> line 3711, in drop_all
> bind._run_visitor(ddl.SchemaDropper,
>   File
> "/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/engine/base.py",
> line 1856, in _run_visitor
> conn._run_visitor(visitorcallable, element, **kwargs)
>   File
> "/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/engine/base.py",
> line 1480, in _run_visitor
> visitorcallable(self.dialect, self,
>   File
> "/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/sql/visitors.py",
> line 121, in traverse_single
> return meth(obj, **kw)
>   File
> "/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/sql/ddl.py", line
> 813, in visit_metadata
> filter_fn=lambda constraint: False
>   File
> "/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/sql/ddl.py", line
> 813, in visit_metadata
> filter_fn=lambda constraint: False
>   File
> "/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/sql/ddl.py", line
> 1067, in sort_tables_and_constraints
> candidate_sort = list(
>   File
> "/home/michael/jython2.7.0/Lib/site-packages/sqlalchemy/sql/ddl.py", line
> 1067, in sort_tables_and_constraints
> candidate_sort = list(
> 

[sqlalchemy] Versioning of Many-to-Many relationships

2012-02-09 Thread Michael Naber
*I have a many to many relationship between musician and genre indicating
that a particular musician performs in the style of a particular genre:
Musician -- musician_genre -- Genre

Musician and Genre are both versioned using VersionedMeta so it is easy for
me to display a history of the attributes for a particular record. The hard
part is displaying the history of the associations between them. For any
particular musician or genre, I want to be able to display the association
historically, for example:

Genere 17:
Time1: [Musician 12]
Time2: [Musician 12,  Musician 3, Musician 5]
Time3: [Musician 12, Musician 6]
etc...

Of course I would also want to perform the complimentary action:

Musician 8:
Time1: [Genre 8]
Time2: [Genre 8, Genre 17]
etc...

Approaches that seem bad to me:
1) Serializing a list of musician IDs directly attached to the genre object
and vice versa.
2) Using VersionedMeta on the association object, musician_genre.

Does anyone have any other ideas as to how I might accomplish this?

Thanks,
Michael*

-- 
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] Question about mutable primary keys and foreign keys

2012-02-06 Thread Michael Naber
I am trying to efficiently update all things that foreign key to a
particular record so that they instead foreign key to a different record. I
provided an example that illustrates the problem I am trying to solve.
Please see my question at the bottom of the code.

Thanks for your help,
Michael


from sqlalchemy import Column, Integer, String, ForeignKey, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker, relationship,
backref

Base = declarative_base()
Session = scoped_session(sessionmaker())

def init_model(dsn):
engine = create_engine(dsn)
Session.configure(bind=engine)
Base.metadata.bind = engine
Base.metadata.create_all(engine)

class Person(Base):
__tablename__ = 'person'
id = Column(Integer, primary_key=True)
name = Column(String(50))
addresses = relationship(Address, backref=person,
 cascade=all, passive_updates=False)
vehicles = relationship(Vehicle, backref=person,
cascade=all, passive_updates=False)

class Address(Base):
__tablename__ = 'address'
id = Column(Integer, primary_key=True)
email = Column(String(50))
person_id = Column(Integer, ForeignKey('person.id'))
#backref: person
def __repr__(self):
return 'id: %s, person_id: %s, email: %s' % \
(self.id, self.person_id, self.email)

class Vehicle(Base):
__tablename__ = 'vehicle'
id = Column(Integer, primary_key=True)
color = Column(String)
kind = Column(String)
person_id = Column(Integer, ForeignKey('person.id'))
#backref: person
def __repr__(self):
return 'id: %s, person_id: %s, kind: %s, color: %s' % \
(self.id, self.person_id, self.kind, self.color)

init_model('sqlite:///:memory:')
s = Session()
s.add_all([Person(name='Mike',
  addresses=[Address(email='mi...@mike.com'),
Address(email='mi...@mike.com')],
  vehicles=[Vehicle(color='red', kind='truck'),
Vehicle(color='white', kind='van')]),
   Person(name='Steve',
  addresses=[Address(email='ste...@steve.com')],
  vehicles=[Vehicle(color='orange', kind='car')])])

mike = s.query(Person).filter_by(name='Mike').one()

'''
I can easily change the person_id value of everything that had a FK to mike
by changing mike.id:
'''

mike.id = 50

for vehicle in s.query(Vehicle).all():
print vehicle.person_id
for address in s.query(Address).all():
print address.person_id

'''
Question:
What would I do if I wanted to take all the things that FK to Mike, and
then FK them to Steve instead?
Not possible to do mike.id = steve.id because primary key must be unique.

Of course in this example I could issue separate updates to Address and
Vehicle which would not be too bad,
but in my real project there are dozens of other classes besides Address
and Vehicle. Is there a more efficient way besides
separate updates?

Thanks,
Michael
'''

-- 
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] Simple question about delete-orphan

2011-11-19 Thread Michael Naber
Thanks, Mike. The docs look like they are a little out of date on this. For
delete-orphan, they say that Note that this option prevents a pending item
of the child’s class from being persisted without a parent present.
http://www.sqlalchemy.org/docs/orm/relationships.html#relationships-api



On Tue, Nov 1, 2011 at 11:00 AM, Michael Bayer mike...@zzzcomputing.comwrote:


 On Nov 1, 2011, at 6:48 AM, Michael Naber wrote:

  Quick question: Why am I allowed to persist an address with no
 person_id? Shouldn't the delete-orphan prohibit this?

 This was the behavior up until 0.7, when the decision was reversed -
 delete-orphan now considers an orphan to be only an object that *had* a
 parent, now does not.   To prevent the insertion of a row that has no
 parent to start with you'd use a NOT NULL constraint on the foreign key.

 The improvement here allows delete-orphan cascade to be used on
 hierarchical structures where the root row has no parent.   No
 functionality is lost for systems where parents are required as that's what
 constraints are for.

 Notes:
 http://www.sqlalchemy.org/trac/wiki/07Migration#Flushingoforphansthathavenoparentisallowed

 --
 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] Simple question about delete-orphan

2011-11-01 Thread Michael Naber
Quick question: Why am I allowed to persist an address with no
person_id? Shouldn't the delete-orphan prohibit this?

Thanks,
Michael


from sqlalchemy import Column, Integer, String, ForeignKey, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker, relationship,
backref

Base = declarative_base()
Session = scoped_session(sessionmaker())

def init_model(dsn):
engine = create_engine(dsn)
Session.configure(bind=engine)
Base.metadata.bind = engine
Base.metadata.create_all(engine)

class Person(Base):
__tablename__ = 'person'
id = Column(Integer, primary_key=True)
name = Column(String(50))
addresses = relationship(Address, backref=person, cascade=all,
delete-orphan)

class Address(Base):
__tablename__ = 'address'
id = Column(Integer, primary_key=True)
email = Column(String(50))
person_id = Column(Integer, ForeignKey('person.id'))
#backref: person

init_model('sqlite:///:memory:')

s = Session()
s.add(Person(name='Isaac'))
s.commit()
s.add(Address(email='zxksa...@gmail.com'))
s.commit()

for adr in s.query(Address).all():
print adr.email
print adr.person_id
'''
Why am I allowed to persist an address with no person_id?
Shouldn't the delete-orphan prohibit this?
'''

-- 
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] Bug in mssql dialect?

2011-03-04 Thread Michael Naber
You are right. Thanks once again.

On Mar 3, 2011, at 11:11, Michael Bayer mike...@zzzcomputing.com wrote:

 That looks certainly like a misconfigured relationship().   Not sure why 
 SQLite would let it pass through (sqlite is in general extremely liberal), 
 but that's clearly a literal string passed to a join expression sent to 
 relationship as in relationship(... primaryjoin=and_(some expression, 
 Edge._discriminator=='use')) or something like that. When using strings 
 for relationship(), the full expression must be a string, not the components.
 
 
 
 On Mar 3, 2011, at 10:55 AM, Michael Naber wrote:
 
 Last line is invalid t-sql. The ‘==’ should just be ‘=’. I get the problem 
 when using mssql but not with sqlite. Saw the bug on sqa version 0.6.6, 
 upgraded to 0.7b2 and still having issue. Please let me know if you need 
 more info and I'll be happy to provide.
  
 Thanks,
 Michael
  
  
 Traceback (most recent call last):
   File C:\Program Files\eclipse-SDK-3.6.2-win32\eclipse\dropins\Pydev 
 1.6.5\plugins\org.python.pydev.debug_1.6.5.2011020317\pysrc\pydevd.py, line 
 1133, in module
 debugger.run(setup['file'], None, None)
   File C:\Program Files\eclipse-SDK-3.6.2-win32\eclipse\dropins\Pydev 
 1.6.5\plugins\org.python.pydev.debug_1.6.5.2011020317\pysrc\pydevd.py, line 
 918, in run
 execfile(file, globals, locals) #execute the script
   File C:\OpsPylonDev\TransformationBA-Trunk\pydev-setup-app.py, line 5, 
 in module
 SetupCommand('setup-app').run(['development.ini'])
   File 
 C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py,
  line 68, in run
 return super(AbstractInstallCommand, self).run(new_args)
   File 
 C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\command.py,
  line 218, in run
 result = self.command()
   File 
 C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py,
  line 456, in command
 self, config_file, section, self.sysconfig_install_vars(installer))
   File 
 C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py,
  line 598, in setup_config
 mod.setup_app, command, filename, section, vars)
   File 
 C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py,
  line 612, in _call_setup_app
 func(command, conf, vars)
   File C:\OpsPylonDev\TransformationBA-Trunk\transformationba\websetup.py, 
 line 34, in setup_app
 insert_data()
   File 
 C:\OpsPylonDev\TransformationBA-Trunk\transformationba\model\data\__init__.py,
  line 42, in insert_data
 inserter.insert()
   File transformationba\model\data\inserters\400technology.py, line 23, in 
 insert
 csharp_app.create_artifacts()
   File 
 C:\OpsPylonDev\TransformationBA-Trunk\transformationba\model\data\technology_data\csharp_app.py,
  line 65, in create_artifacts
 parent.uses.append(component)
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\ext\associationproxy.py,
  line 189, in __get__
 proxy = self._new(_lazy_collection(obj, self.target_collection))
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\ext\associationproxy.py,
  line 233, in _new
 self.collection_class = util.duck_type_collection(lazy_collection())
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\ext\associationproxy.py,
  line 335, in __call__
 return getattr(obj, self.target)
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\attributes.py,
  line 162, in __get__
 return self.impl.get(instance_state(instance),dict_)
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\attributes.py,
  line 414, in get
 value = self.callable_(state, passive)
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\strategies.py,
  line 542, in _load_for_state
 result = q.all()
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\query.py,
  line 1636, in all
 return list(self)
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\query.py,
  line 1746, in __iter__
 return self._execute_and_instances(context)
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\query.py,
  line 1752, in _execute_and_instances
 close_with_result=True).execute(querycontext.statement, self._params)
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py,
  line 1259, in execute
 params)
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py,
  line 1392, in _execute_clauseelement
 compiled_sql, distilled_params
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py,
  line 1500, in _execute_context
 context)
   File 
 C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy

[sqlalchemy] Bug in mssql dialect?

2011-03-03 Thread Michael Naber
Last line is invalid t-sql. The ‘==’ should just be ‘=’. I get the problem
when using mssql but not with sqlite. Saw the bug on sqa version 0.6.6,
upgraded to 0.7b2 and still having issue. Please let me know if you need
more info and I'll be happy to provide.

Thanks,
Michael


Traceback (most recent call last):
  File C:\Program Files\eclipse-SDK-3.6.2-win32\eclipse\dropins\Pydev
1.6.5\plugins\org.python.pydev.debug_1.6.5.2011020317\pysrc\pydevd.py, line
1133, in module
debugger.run(setup['file'], None, None)
  File C:\Program Files\eclipse-SDK-3.6.2-win32\eclipse\dropins\Pydev
1.6.5\plugins\org.python.pydev.debug_1.6.5.2011020317\pysrc\pydevd.py, line
918, in run
execfile(file, globals, locals) #execute the script
  File C:\OpsPylonDev\TransformationBA-Trunk\pydev-setup-app.py, line 5,
in module
SetupCommand('setup-app').run(['development.ini'])
  File
C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py,
line 68, in run
return super(AbstractInstallCommand, self).run(new_args)
  File
C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\command.py,
line 218, in run
result = self.command()
  File
C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py,
line 456, in command
self, config_file, section, self.sysconfig_install_vars(installer))
  File
C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py,
line 598, in setup_config
mod.setup_app, command, filename, section, vars)
  File
C:\Python27\lib\site-packages\pastescript-1.7.3-py2.7.egg\paste\script\appinstall.py,
line 612, in _call_setup_app
func(command, conf, vars)
  File C:\OpsPylonDev\TransformationBA-Trunk\transformationba\websetup.py,
line 34, in setup_app
insert_data()
  File
C:\OpsPylonDev\TransformationBA-Trunk\transformationba\model\data\__init__.py,
line 42, in insert_data
inserter.insert()
  File transformationba\model\data\inserters\400technology.py, line 23, in
insert
csharp_app.create_artifacts()
  File
C:\OpsPylonDev\TransformationBA-Trunk\transformationba\model\data\technology_data\csharp_app.py,
line 65, in create_artifacts
parent.uses.append(component)
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\ext\associationproxy.py,
line 189, in __get__
proxy = self._new(_lazy_collection(obj, self.target_collection))
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\ext\associationproxy.py,
line 233, in _new
self.collection_class = util.duck_type_collection(lazy_collection())
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\ext\associationproxy.py,
line 335, in __call__
return getattr(obj, self.target)
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\attributes.py,
line 162, in __get__
return self.impl.get(instance_state(instance),dict_)
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\attributes.py,
line 414, in get
value = self.callable_(state, passive)
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\strategies.py,
line 542, in _load_for_state
result = q.all()
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\query.py,
line 1636, in all
return list(self)
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\query.py,
line 1746, in __iter__
return self._execute_and_instances(context)
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\orm\query.py,
line 1752, in _execute_and_instances
close_with_result=True).execute(querycontext.statement, self._params)
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py,
line 1259, in execute
params)
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py,
line 1392, in _execute_clauseelement
compiled_sql, distilled_params
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py,
line 1500, in _execute_context
context)
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\base.py,
line 1493, in _execute_context
context)
  File
C:\Python27\lib\site-packages\sqlalchemy-0.7b2-py2.7.egg\sqlalchemy\engine\default.py,
line 325, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', [42000]
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '='.
(102) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL
Server]Statement(s) could not be prepared. (8180)) uSELECT edge.id AS
edge_id, edge.tail_node_id AS edge_tail_node_id, edge.head_node_id AS
edge_head_node_id, edge._discriminator AS edge__discriminator \nFROM edge
\nWHERE edge.tail_node_id = ? AND Edge._discriminator=='use' (69,)

-- 
You received this message because you are subscribed to the 

[sqlalchemy] Using the foreign_keys relationship argument with declarative

2011-02-11 Thread Michael Naber
If I'm creating a relationship to a class MyRelatedClass using
declarative syntax, and I need to assign a column from MyRelatedClass
to the foreign_keys argument, it seems I have to say
foreign_keys=[MyRelatedClass.__mapper__.c.relate_id]. Is there any way
to just do something in the declarative style, such as:
foreign_keys=[MyRelatedClass.relate_id] with the quotes?

Thanks,
Michael

-- 
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] Re: Using the foreign_keys relationship argument with declarative

2011-02-11 Thread Michael Naber
Thanks for your help. Sorry if I wasn't clear. I was referring to the
foreign_keys keyword argument to relationship, not to ForeignKey. Here is a
link to the relevant doc:
http://www.sqlalchemy.org/docs/orm/relationships.html?highlight=relationship#sqlalchemy.orm.relationship

Thanks,
Michael

On Fri, Feb 11, 2011 at 7:45 AM, dalia dalia@gmail.com wrote:

 I'm not sure I understood your question correctly as I'm very new to
 sqlalchemy, still I thought u need to know how to declare ForeignKeys
 in declarative style. Here is how u can declare it ; for example,
 suppose you have 2 tables -

 class A(Base):
 __tablename__ = 'a_table'
 id = Column(Integer, primary_key=True)
somecol1 = Column(Unicode(20))

 class B(Base):
__tablename__='b_table'
id = Column(Integer, primary_key=True)
a_id = Column(Integer, ForeignKey('a_table.id'))
somecol2 = Column(Unicode(20))

 here a_id column of b_table is foreignkey related to the id column of
 a_table

 On Feb 11, 9:20 am, Michael Naber mickey...@gmail.com wrote:
  If I'm creating a relationship to a class MyRelatedClass using
  declarative syntax, and I need to assign a column from MyRelatedClass
  to the foreign_keys argument, it seems I have to say
  foreign_keys=[MyRelatedClass.__mapper__.c.relate_id]. Is there any way
  to just do something in the declarative style, such as:
  foreign_keys=[MyRelatedClass.relate_id] with the quotes?
 
  Thanks,
  Michael

 --
 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] Adjacency List Relationship in a Child Class

2011-01-23 Thread Michael Naber
I'm still having trouble getting an adjacency list relationship to
work within a child class (Department class in this example), and am
hoping someone might offer some insight:

class Node(Base):
__tablename__ = 'node'
id = Column(Integer, primary_key=True)
name = Column(String(100))
discriminator = Column('discriminator', String(50))

class Department(Node):
__tablename__ = 'department'
__mapper_args__ = {'polymorphic_identity': 'department'}
id = Column(Integer, ForeignKey('node.id'), primary_key=True)
description = Column(Text)
parent_department_id = Column(Integer,
ForeignKey('department.id'))
parent_department = relationship(Department,
 
backref=backref(subdepartments),
 remote_side=id)

Thanks,
Michael Naber

-- 
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] Adjacency List Relationship in a Child Class

2011-01-18 Thread Michael Naber
Whenever I try to establish an adjacency list relationship within a
child class (Department -- Parent Department in this case) the orm
complains about foreign key columns present in both the parent and
child class, and won’t construct the mapping. Below is an example
illustrating the problem. I'd appreciate any insight.

Thanks,
Michael Naber


from sqlalchemy.orm import scoped_session, sessionmaker, relationship,
backref
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine, Column, Integer, String,
ForeignKey, Text, Date

Session = scoped_session(sessionmaker())
Base = declarative_base()

engine = create_engine('sqlite:///data.db')
Session.configure(bind=engine)

class Node(Base):
__tablename__ = 'node'
id = Column(Integer, primary_key=True)
name = Column(String(100))
discriminator = Column('discriminator', String(50))


class Department(Node):
__tablename__ = 'department'
__mapper_args__ = {'polymorphic_identity': 'department'}
id = Column(Integer, ForeignKey('node.id'), primary_key=True)
description = Column(Text)
parent_department_id = Column(Integer,
ForeignKey('department.id'))
parent_department = relationship(Department,
 
primaryjoin=Department.parent_department_id==Department.id,
 
foreign_keys=Department.parent_department_id,
 
backref=backref(subdepartments), remote_side=Department.id)

Base.metadata.drop_all(checkfirst=True, bind=Session.bind)
Base.metadata.create_all(bind=Session.bind)

s = Session()

d = Department(name='Great Department', description='some text')
s.add(d)
s.commit()

for dept in s.query(Department).all():
print dept.id
print dept.name

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