OK, just in case anyone else is foolishly trying  to run SQLA on ironpython,
here's the workaround I've found:

instead of attempting to use the mapper directly on the join:

j = join(movies_table,md_table).join(directors_table)
> mapper(MoviesAndDirectors,j) #ipy errors here
>

use a mapper on a select based on the join:

mapper(MoviesAndDirectors,j.select(use_labels=True).alias('moviesanddirectors'))
>

seems to be working ok for now.

one final, polite plea - how can i run the sqla test suite, to see what
other bugs might be lurking?

cheers,
Harry


On Thu, Jul 8, 2010 at 10:52 AM, Harry Percival <[email protected]>wrote:

> Here's the source code of my test - let me know if I'm doing anything wrong
> here
>
> from sqlalchemy import create_engine
> from sqlalchemy.orm import mapper
> from sqlalchemy.sql.expression import join
> from sqlalchemy.orm.session import sessionmaker
> from sqlalchemy.schema import MetaData
> import traceback
>
> try:
>     import clr
>     import os
>     import sys
>     sys.path.append(os.path.join(os.path.abspath(os.path.curdir),'sqlite'))
>     clr.AddReference('Ironpython.Sqlite')  #need this for sqlite to work on
> ironpython. refers to a dll in zip file.
> except:
>     #not ipy
>     pass
> #from sqlalchemy.ext.sqlsoup import SqlSoup #sqlsoup also errors
>
> engine = create_engine('sqlite:///moviedemo_simple.db3')  #moviedemo file
> also in zip file.
> Session = sessionmaker(bind=engine)
> class Movies(object):
>     pass
> class Directors(object):
>     pass
> class Genres(object):
>     pass
> class MoviesAndDirectors(object):
>     pass
>
> meta = MetaData()
> meta.reflect(bind=engine)
> all_tables = meta.tables
>
> movies_table = all_tables['movies']
> genres_table = all_tables['genres']
> directors_table = all_tables['directors']
> md_table = all_tables['movie_directors']
>
> mapper(Movies,movies_table)
> mapper(Directors,directors_table)
> mapper(Genres,genres_table)
>
> session = Session()
> print session.query(Movies).all()[0]
> print session.query(Directors).all()[0]
>
> j = join(movies_table,md_table).join(directors_table)
> try:
>
>     mapper(MoviesAndDirectors,j)#ipy errors here
>     mad1 = session.query(MoviesAndDirectors).all()[0]
>     print mad1
> except Exception, e:
>     print 'caught exception',e
>     last_error = e
>     traceback.print_exc()
>
> how can i run the sqlalchemy test suite?  I see it needs nose, i've
> installed that.  but i'm not clear what command to run to launch tests.
>
> rgds,
> harry
>
>
> On Tue, Jul 6, 2010 at 6:40 PM, Harry Percival 
> <[email protected]>wrote:
>
>> Hi Michael,
>>
>> thanks for replying - the reason I attached a zipfile is because sqlite
>> isn't supported natively on ironpython, so I've had to include the source
>> and a dll for it.  So, if you did have time to open it up and take a peek,
>> I'd very much appreciate it.
>>
>> Alternatively, how can I run the sqla unit tests?
>>
>>
>> On Tue, Jul 6, 2010 at 3:56 PM, Michael Bayer 
>> <[email protected]>wrote:
>>
>>>
>>> On Jul 6, 2010, at 4:18 AM, Harry Percival wrote:
>>>
>>> Hi,
>>>
>>> I've got an error which occurs in ironpython but not in cpython. can
>>> anyone replicate?  See attached. I'm using IPY 2.6.
>>>
>>> *<string>:1: DeprecationWarning: object.__init__() takes no parameters
>>>> for type _keyed_weakref
>>>> <string>:1: DeprecationWarning: object.__init__() takes no parameters
>>>> for type KeyedRef
>>>> <Movies object at 0x0000000000000034>
>>>> <Directors object at 0x0000000000000038>
>>>> caught exception 'NoneType' object has no attribute 'set'
>>>> Traceback (most recent call last):
>>>>  File "D:\workspace\resolver\test_multitable.py", line 54, in <module>
>>>>    mapper(MoviesAndDirectors,j)#ipy errors here
>>>>  File "D:\workspace\resolver\sqlalchemy\orm\__init__.py", line 818, in
>>>> mapper
>>>>    return Mapper(class_, local_table, *args, **params)
>>>>  File "D:\workspace\resolver\sqlalchemy\orm\mapper.py", line 210, in
>>>> __init__
>>>>    self._configure_properties()
>>>>  File "D:\workspace\resolver\sqlalchemy\orm\mapper.py", line 563, in
>>>> _configure_properties
>>>>    self._configure_property(column_key,
>>>>  File "D:\workspace\resolver\sqlalchemy\orm\mapper.py", line 755, in
>>>> _configure_property
>>>>    prop.instrument_class(self)
>>>>  File "D:\workspace\resolver\sqlalchemy\orm\properties.py", line 87, in
>>>> instrument_class
>>>>    attributes.register_descriptor(
>>>>  File "D:\workspace\resolver\sqlalchemy\orm\attributes.py", line 1424,
>>>> in register_descriptor
>>>>    manager.instrument_attribute(key, descriptor)
>>>>  File "D:\workspace\resolver\sqlalchemy\orm\attributes.py", line 1012,
>>>> in instrument_attribute
>>>>    self.install_descriptor(key, inst)
>>>>  File "D:\workspace\resolver\sqlalchemy\orm\attributes.py", line 1054,
>>>> in install_descriptor
>>>>    setattr(self.class_, key, inst)
>>>>  File "D:\workspace\resolver\sqlalchemy\orm\attributes.py", line 151, in
>>>> __set__
>>>>    self.impl.set(instance_state(instance), instance_dict(instance),
>>>> value, None)
>>>> AttributeError: 'NoneType' object has no attribute 'set'
>>>> *
>>>
>>>
>>>
>>>
>>> does this look like a bug with ironpython? if so, I'll report it to the
>>> developers, but i need a little more help tracking down exactly what's going
>>> wrong...
>>>
>>>
>>> its likely some slightly different behavior in ironpython regarding
>>> descriptors.   If you don't have a lot of SQLA experience, it would be
>>> extremely difficult to get SQLA running with a new Python interpreter.
>>> Getting it to run on Jython took a huge amount of effort and weeks/months of
>>> bughunting, both in SQLA and Jython itself.  We currently don't have any
>>> resources to get it to work on IronPython as well.
>>>
>>>
>>>
>>> For bonus points:  In the attached database, there's a many-to-many
>>> relationship between 'movies' and 'directors' via a simple joining table.
>>>  How come SQLA isn't able to figure this out on its own and let me just
>>> join(movies_table, directors_table)? It seems unneccesary to have to specify
>>> the extra join(movies_table,md_table).join(directors_table)...
>>>
>>>
>>> I don't generally open full zipfiled applications, so if you want to
>>> attach a succinct, single-file code example that would help.   If you have
>>> relationships between two classes, the relationship() function is used to
>>> establish that, which would allow query.join(Movie.directors) to generate
>>> the joins automatically.
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "sqlalchemy" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<sqlalchemy%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/sqlalchemy?hl=en.
>>>
>>
>>
>>
>> --
>> ------------------------------
>> Harry J.W. Percival
>> ------------------------------
>> Italy Mobile: +39 389 095 8959
>> UK Mobile:  +44 (0) 78877 02511 (may be turned off)
>> Skype:         harry.percival
>> Email:          [email protected]
>>
>
>
>
> --
> ------------------------------
> Harry J.W. Percival
> ------------------------------
> Italy Mobile: +39 389 095 8959
> UK Mobile:  +44 (0) 78877 02511 (may be turned off)
> Skype:         harry.percival
> Email:          [email protected]
>



-- 
------------------------------
Harry J.W. Percival
------------------------------
Italy Mobile: +39 389 095 8959
UK Mobile:  +44 (0) 78877 02511
Skype:         harry dot percival

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
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.

Reply via email to