In Python, you have to pass "self" as first argument to all methods of a class:

class MyQuery(sqlalchemy.orm.query.Query):

    def __init__(self, *arg, **kw):
        ...

Alex

2009/9/18 Christian Démolis <christiandemo...@gmail.com>:
> Hello,
>
> Thx for the answer, thx to Alexandre to translate my mail.
>
> Sorry, i continue in english, i tried to do that at the end of my
> declaration file :
>
> Base.metadata.create_all(engine)
> import sqlalchemy.orm.query
> class MyQuery(sqlalchemy.orm.query.Query):
>     def __init__(*arg, **kw):
>        self._populate_existing = True
>        super(MyQuery, self).__init__(*arg, **kw)
> Session = scoped_session(sessionmaker(autocommit=True, bind=engine))
> session = Session()
> print "Le temps de déclaration SQL ALCHEMY", time.time()-xref
>
> Is it correct? i m not very good in subclassing :S
> It seems to not work.
> When i add a print in the __init__, i never see it during the execution of
> my program so MyQuery is not used i think.
> Can u tell me where should i subclass Query? In the declaration.py? in
> module sqlalchemy?
> I tried to add myquery here
> Session = scoped_session(sessionmaker(autocommit=True, bind=engine,
> query_cls=MyQuery))
> but it does error
>   File
> "C:\Python25\lib\site-packages\sqlalchemy-0.5.6-py2.5.egg\sqlalchemy\orm\
> session.py", line 899, in query
>     return self._query_cls(entities, self, **kwargs)
>   File "Z:\Declaration.py", line 1451, in __init__
>     self._populate_existing = True
> NameError: global name 'self' is not defined
>
> I can t touch to the sqlalchemy module because the interpreter and libraries
> are installed on multiple computers which execute one unique code on a
> shared network path.
> So it's more easy to change my source code than sqlalchemy code...
>
> i just want to change session.query behavior without change the code of
> sqlalchemy itself, please help me.
>
> 2009/9/17 Michael Bayer <mike...@zzzcomputing.com>
>>
>> Alexandre Conrad wrote:
>> >
>> > Christian,
>> >
>> > 2009/9/17 Christian Démolis <christiandemo...@gmail.com>:
>> >> Bonjour,
>> >>
>> >> Tu es français je pense au vu de ton prénom.
>> >> Je continue donc en français.
>> >
>> > Nice guess.
>> >
>> > I understand it feels more comfortable writing in French rather than
>> > in English, but many people are reading this list (or is only Mike
>> > doing support? ;) ) and may be interested at the topic. And more eyes
>> > and brains may answer your question. So please keep conversations on
>> > this list to its native language - English. If you really want to
>> > switch to a non-English language with someone particular, please
>> > exchange off-list, but I believe you'll dramatically reduce your
>> > chances of solving your problem.
>> >
>> > So for the record, you were explaining that you have 25000 lines of
>> > code and you'd like to avoid to add refresh or
>> > session.query().populate_existing() all around the place. You have
>> > attempted to override the query method but couldn't make it. You have
>> > pointed out the PreFilteredQuery
>> > http://www.sqlalchemy.org/trac/wiki/UsageRecipes/PreFilteredQuery but
>> > was unsuccessful achieving what you wanted.
>> >
>> > Sorry, maybe someone else can help you there. I haven't played with
>> > Query overriding myself.
>>
>> a Query subclass which just says
>>
>> def __init__(*arg, **kw):
>>    self._populate_existing = True
>>    super(MyQuery, self).__init__(*arg, **kw)
>>
>> should do it....
>>
>>
>>
>>
>>
>> >
>> > Alex
>> >
>> > >
>> >
>>
>>
>>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to