tg and SA auto flush()

2 views
Skip to first unread message

Jose Soares

unread,
Mar 28, 2007, 11:38:14 AM3/28/07
to turbo...@googlegroups.com
Hi all,

I'm having some problems with SA flush(),
because tg does all the time an automatically flush()...
I found I can use the SA expunge() function to remove something unwanted
from UofW
but it is very ugly.

In this example, I instanciate the class Nation to use the search method.
I must use session.expunge(instance) to avoid the SA attempt to insert a
new row into the database.

n=Nation()
ret = n.search(limit=limit, offset=offset, order_by=sort)
session.expunge(n)

I would like to know if is there some flag to tell tg to do not
autoflush anymore.

Thank you,

jo

Jose Soares

unread,
Mar 28, 2007, 2:40:28 PM3/28/07
to turbo...@googlegroups.com
Jose Soares ha scritto:
here the traceback...

Module paste.evalexception.middleware:*293* in |respond|
<http://10.0.0.114:8000/nazione/#>
|>> <http://10.0.0.114:8000/nazione/#>return_iter *=* list*(*app_iter*)*|
Module cherrypy._cpwsgi:*75* in |wsgiApp|
<http://10.0.0.114:8000/nazione/#>
|>> <http://10.0.0.114:8000/nazione/#>environ*[*'wsgi.input'*]**)*|
Module cherrypy._cphttptools:*72* in |run|
<http://10.0.0.114:8000/nazione/#>
|>> <http://10.0.0.114:8000/nazione/#>self*.*_run*(**)*|
Module cherrypy._cphttptools:*105* in |_run|
<http://10.0.0.114:8000/nazione/#>
|>> <http://10.0.0.114:8000/nazione/#>self*.*main*(**)*|
Module cherrypy._cphttptools:*254* in |main|
<http://10.0.0.114:8000/nazione/#>
|>> <http://10.0.0.114:8000/nazione/#>body *=*
page_handler*(****virtual_path*,* ****self*.*params*)*|
Module ?:*3* in |index| <http://10.0.0.114:8000/nazione/#>
Module turbogears.identity.conditions:*235* in |require|
<http://10.0.0.114:8000/nazione/#>
|>> <http://10.0.0.114:8000/nazione/#>*return* fn*(*self*,* ***args*,*
****kwargs*)*|
Module ?:*3* in |index| <http://10.0.0.114:8000/nazione/#>
Module turbogears.controllers:*334* in |expose|
<http://10.0.0.114:8000/nazione/#>
|>> <http://10.0.0.114:8000/nazione/#>output *=*
database*.*run_with_transaction*(*|
Module dispatch.functions:*5* in |run_with_transaction|
<http://10.0.0.114:8000/nazione/#>
Module turbogears.database:*352* in |sa_rwt|
<http://10.0.0.114:8000/nazione/#>
|>> <http://10.0.0.114:8000/nazione/#>retval *=*
dispatch_exception*(*e*,*args*,*kw*)*|
Module turbogears.database:*342* in |sa_rwt|
<http://10.0.0.114:8000/nazione/#>
|>> <http://10.0.0.114:8000/nazione/#>transaction*.*commit*(**)*|
Module sqlalchemy.orm.session:*62* in |commit|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.orm.session:*294* in |flush|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.orm.unitofwork:*213* in |flush|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.orm.unitofwork:*368* in |execute|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.orm.unitofwork:*535* in |execute|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.orm.unitofwork:*941* in |execute|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.orm.unitofwork:*958* in |execute_save_steps|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.orm.unitofwork:*946* in |save_objects|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.orm.unitofwork:*523* in |_save_objects|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.orm.mapper:*1192* in |save_obj|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.engine.base:*444* in |execute|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.engine.base:*484* in |execute_clauseelement|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.engine.base:*503* in |execute_compiled|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.engine.base:*499* in |proxy|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.engine.base:*547* in |_execute_raw|
<http://10.0.0.114:8000/nazione/#>
Module sqlalchemy.engine.base:*566* in |_execute|
<http://10.0.0.114:8000/nazione/#>
*sqlalchemy.exceptions.SQLError: ('(IntegrityError) null value in column
"code" violates not-null constraint\n', <bound method Controller.index
of <sic.controllers.nation.Controller instance at 0xb6b0b02c>>) 'INSERT
INTO nation (code, name, code_cia, zone) VALUES (%(code)s,
%(code_cia)s, %(name)s, %(zone)s' {'zone': None, 'code': None, 'name':
None, 'code_cia': None}* |<<
<http://10.0.0.114:8000/nazione/#> app_iter *=*
self*.*application*(*environ*,* detect_start_response*)*
*try**:*
return_iter *=* list*(*app_iter*)*
*return* return_iter
*finally**:*| |<<
<http://10.0.0.114:8000/nazione/#> response *=*
request*.*run*(*requestLine*(*environ*)**,*
translate_headers*(*environ*)**,*
environ*[*'wsgi.input'*]**)*
s*,* h*,* b *=* response*.*status*,*
response*.*header_list*,* response*.*body
exc *=* None| |<<
<http://10.0.0.114:8000/nazione/#>
cherrypy.profiler.run(self._run)
else:
self._run()

if self.method == "HEAD":| |<<
<http://10.0.0.114:8000/nazione/#>
applyFilters('before_main')
if self.execute_main:
self.main()
break
except cherrypy.InternalRedirect, ir:| |<<
<http://10.0.0.114:8000/nazione/#> self*.*object_path *=* '/' *+*
'/'*.*join*(*object_path*[**1**:**]**)*
*try**:*
body *=* page_handler*(****virtual_path*,*
****self*.*params*)*
*except* Exception*,* x*:*
*if* hasattr*(*x*,* "args"*)**:*| |<<
<http://10.0.0.114:8000/nazione/#> if predicate is None or \
predicate.eval_with_object(current, errors):
return fn(self, *args, **kwargs)
except IdentityException, e:
errors= [str(e)]| |<<
<http://10.0.0.114:8000/nazione/#> *else**:*
cherrypy*.*request*.*in_transaction *=* True
output *=* database*.*run_with_transaction*(*
func*.*_expose*,* func*,* accept*,*
func*.*_allow_json*,*
***args*,* ****kw*)*| |<<
<http://10.0.0.114:8000/nazione/#> *except* Exception*,* e*:*
transaction*.*rollback*(**)*
retval *=* dispatch_exception*(*e*,*args*,*kw*)*
*return* retval| |<< <http://10.0.0.114:8000/nazione/#> *try**:*
retval *=* func*(****args*,* ****kw*)*
transaction*.*commit*(**)*
*except*
*(*cherrypy*.*HTTPRedirect*,*cherrypy*.*InternalRedirect*)**:*
*try**:*|

Paul Johnston

unread,
Mar 28, 2007, 9:43:08 AM3/28/07
to turbo...@googlegroups.com
Hi Jose,

> n=Nation()
> ret = n.search(limit=limit, offset=offset, order_by=sort)
> session.expunge(n)
>
>

How about you make search() a classmethod, and use Nation.search instead
of creating an instance.

Paul

Jose Soares

unread,
Mar 28, 2007, 4:40:40 PM3/28/07
to turbo...@googlegroups.com
Paul Johnston ha scritto:
yes, in this case it could be a good choice...

thank you, Paul

jo


Reply all
Reply to author
Forward
0 new messages