Discussion:
[Erp5-dev] Modifying ZODB from zopectl debug - is it possible?
Łukasz Nowak
2007-09-24 13:01:09 UTC
Permalink
Hello,

I need to do some conversion on data in my zodb. I've found on plone
debugging page[1] that using get_transaction().commit() it will be
possible to save changes into ZODB.

That is my session:

zopectl> debug
portal = app.erp5
r = portal.product_module['1']
r.setTitle('Testing...1...2...3')
get_transaction().commit()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File
"/home/shufla/work/erp5instance/Products/ERP5Type/patches/Transaction.py",
line 89, in commit
self._commit_prepare(jars, subjars, subtransaction)
File
"/home/shufla/work/erp5instance/Products/ERP5Type/patches/Transaction.py",
line 169, in _commit_prepare
tpc_prepare(self)
File
"/home/shufla/work/erp5instance/Products/CMFActivity/ActivityBuffer.py",
line 165, in tpc_prepare
activity.prepareQueueMessageList(self._activity_tool, message_list)
File
"/home/shufla/work/erp5instance/Products/CMFActivity/Activity/SQLDict.py",
line 98, in prepareQueueMessageList
activity_tool.SQLDict_writeMessageList( uid_list = uid_list,
AttributeError: SQLDict_writeMessageList

Hm. Unfortunately my knowledge about Zope integrals patched by ERP5 is
not enough to even *understand* why not.

So that's my question - is it possible and how to make some changes in
zopectl debugger? If not this way, how may I do it? I was looking for
some documentation about it, but nothing appropriate was found.
zope = app.acl_users.getUserById('zope')
zope = zope.__of__(app.acl_users)
from AccessControl.SecurityManagement import newSecurityManager
newSecurityManager(None, zope)
where 'zope' if 'superuser' with all roles do not change anything...

Regards,
Luke

[1] http://docs.neuroinf.de/programming-plone/debug
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...''
Pelletier Vincent
2007-09-24 13:27:50 UTC
Permalink
Post by Łukasz Nowak
r.setTitle('Testing...1...2...3')
At this step, you modify the 'r' document, which causes an activity to be
created to reindex the object. But the activity is kept in a buffer unitll
transaction is actually commited...
Post by Łukasz Nowak
get_transaction().commit()
[...]
Post by Łukasz Nowak
"/home/shufla/work/erp5instance/Products/CMFActivity/ActivityBuffer.py",
line 165, in tpc_prepare
activity.prepareQueueMessageList(self._activity_tool, message_list)
Now the transaction is being commited, and activity buffer gets flushed to SQL
tables (in the SQLDict and SQLQueue cases).
Post by Łukasz Nowak
File
"/home/shufla/work/erp5instance/Products/CMFActivity/Activity/SQLDict.py",
line 98, in prepareQueueMessageList
activity_tool.SQLDict_writeMessageList( uid_list = uid_list,
AttributeError: SQLDict_writeMessageList
But to do so it requires to access some ZSQLMethods which are in portal_skins,
and fails to access them.

There are multiple things which are usualy setup when site is accessed through
regular path which might be missing in your case, causing that error.
If you want to modify things by hand and are able to access your site in a
"regular" way, you might want to invoque pdb [1].

If not, you will probably have to find out what needs to be initialised.
There is something initialized in the REQUEST object by portal_skins which
tells the skin selection used, but there should be a fallback on "View",
which should contain "activity" skin folder, hence allowing to access
SQLDict_writeMessageList and the like.

[1] http://www.erp5.org/Discussion/TestingIdeas?highlight=%28pdb%29
--
Vincent Pelletier
Jérome Perrin
2007-09-24 13:29:13 UTC
Permalink
Post by Pelletier Vincent
If not, you will probably have to find out what needs to be initialised.
from Testing.makerequest import makerequest
portal = makerequest(app.erp5)
J?rome
Łukasz Nowak
2007-09-24 13:39:18 UTC
Permalink
Hello,

On 2007-09-24, 15:29:13
Post by Pelletier Vincent
If not, you will probably have to find out what needs to be
initialised.
from Testing.makerequest import makerequest
portal = makerequest(app.erp5)
Great! That's it! I think I wouldn't be able to find it out alone.
Which page on wiki is appropriate for this tip?

Regards,
Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...''
Jérome Perrin
2007-09-24 14:46:25 UTC
Permalink
Post by Łukasz Nowak
Hello,
On 2007-09-24, 15:29:13
Post by Pelletier Vincent
If not, you will probably have to find out what needs to be
initialised.
from Testing.makerequest import makerequest
portal = makerequest(app.erp5)
Great! That's it! I think I wouldn't be able to find it out alone.
Which page on wiki is appropriate for this tip?
Maybe http://www.erp5.org/HowToDebugERP5

J?rome
Łukasz Nowak
2007-09-25 15:15:02 UTC
Permalink
Hello,

On 2007-09-24, 16:46:25
Post by Jérome Perrin
Maybe http://www.erp5.org/HowToDebugERP5
I wrote some about it.

Last question - is such playing with zopectl debug ZEO friendly?

Regards,
Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...''
Jérome Perrin
2007-09-28 15:01:49 UTC
Permalink
Post by Łukasz Nowak
Hello,
On 2007-09-24, 16:46:25
Post by Jérome Perrin
Maybe http://www.erp5.org/HowToDebugERP5
I wrote some about it.
Last question - is such playing with zopectl debug ZEO friendly?
Yes it should, but if you get a conflict error, you have to restart the
transaction correctly.

Having an external method calling pdb is IMHO much easier than using
zopectl debug (at least in development environment)

J?rome
Pelletier Vincent
2007-09-28 17:26:54 UTC
Permalink
Post by Jérome Perrin
Yes it should, but if you get a conflict error, you have to restart the
transaction correctly.
BTW, when I have to track down a problem where an exception gets raized, I use
the following code:

try:
[code to check]
except:
import pdb; pdb.set_trace()
raise

Thanks to the last raise, everything stays fine even if I mistakenly let code
execution continue...
Probably a good habit to take ;) .
--
Vincent Pelletier
Jean-Paul Smets
2007-09-29 09:05:23 UTC
Permalink
Post by Pelletier Vincent
Post by Jérome Perrin
Yes it should, but if you get a conflict error, you have to restart the
transaction correctly.
BTW, when I have to track down a problem where an exception gets raized, I use
[code to check]
import pdb; pdb.set_trace()
raise
Thanks to the last raise, everything stays fine even if I mistakenly let code
execution continue...
Probably a good habit to take ;) .
I would recommend you to add
except ConflictError:

(at least to remind everyone how important it is not to catch conflict
errors).

JPS.
--
Jean-Paul Smets-Solanes, Nexedi CEO - Tel. +33(0)6 62 05 76 14
Nexedi: Consulting and Development of Libre / Open Source Software
http://www.nexedi.com
ERP5: Libre/ Open Source ERP Software for small and medium companies
http://www.erp5.org
Loading...