Hi all,
I've made some progress in using the collective.tin toolkit including
- MySQL_python
- SQLAlchemy 0.4.7p1
- zope.sqlalchemy 0.3
- collective.lead 1.1dev-r66822
- collective.mercury 0.1dev-r66833
- collective.tin 0.3dev
Among other things I've
- migrated to MySql 5.0.41 a legacy MsAccess database, comprising many
tables
- constructed and executed a buildout.cfg starting from the base buildout
for Plone 3.1.4
- created the skeleton of an application product fulbright.grants, as a
development egg
- succeded to generate, for most of the tables, with collective.mercury, the
modules db.py, automodel.py and autointerfaces.py
The schema of the original database is quite simple. It includes:
- a master table representing grants awarded by an institution
- a dozen auxiliary tables used to enumerate and code allowed values for the
columns of the master table.
Each table has a numeric primary key (INT) and a number of VARCHAR colums.
I've started, in the "model.py" module of my product to define a couple of
classes for each of the auxiliary tables.
E.g., in the case of the table "full_comuni", enumerating cities/towns (with
country, region, province information):
- the container class (a folderish object in the ZODB) "CityTownFolder"
- the item class (no ZODB stub) "full_comuniTable" (= CityTown).
I've succeded to define and use the above couple of classes (and to create
an instance of the container class) for 2 auxiliary tables in MySql.
The items inside are listed by Plone in the default view of the container
object and can also be edited.
But, whenever a table includes a value with an accented letter (from the
Italian alphabet), I get an exception such as:
KeyError: '16578'
where the value shown is the value of the primary key of a row containing a
field value with an accented letter.
The KeyError exception is raised by the "__getitem__" method of the class
RDBMSContainer in collective.tin/collective/tin/container.py.
I've put a pdb.trace() instruction slightly upstream, in the "get" method of
the same class, just after the "except ValueError:" line.
I enclose, at the end of this post:
- the transcript of my debugging
- some configuration information
- the complete error log.
I am 99% certain that the problem is related to some bad handling of the
non-ASCII characters (the accented letters).
But I cannot understand
- if some configuration of my software or of the MySql database isn't ok
- if there is some bug in the underlying software and where (collective.tin,
sqlalchemy, ..)
- how to investigate the presumed bug.
I would greatly appreciate any suggestions.
Thank you very much in advance, Giovanni Toffoli
==========
This is the transcript of my debugging:
c:\plone3\plone3\src\collective.tin\collective\tin\container.py(95)get()
-> return default
(Pdb) l
90 clause = sql.and_(*(col==key for col, key in
zip(self.keycolumns, keys)))
91 returned = self.query.filter(clause).all() # this should
only ever be one item long
92 except ValueError:
93 import pdb
94 pdb.set_trace()
95 -> return default
96 if not returned:
97 return default
98 assert len(returned) == 1, "Unexpectedly returned more than
one row"
99 ob = returned[0]
100 #if getattr(ob, '_v__object_deleted__', None): # maybe later
(Pdb) p clause
<sqlalchemy.sql.expression._BinaryExpression object at 0x07320F90>
(Pdb) p self.query.filter(clause)
<sqlalchemy.orm.query.Query object at 0x07323DD0>
(Pdb) objects = self.query.filter(clause).all()
(Pdb) p objects
[<fulbright.grants.model.full_comuniTable object at 0x0739A1B0>]
(Pdb) object = objects[0]
(Pdb) p object
<fulbright.grants.model.full_comuniTable object at 0x0739A1B0>
(Pdb) p object.COMU_COD
16578L
(Pdb) p object.COMU_PROV
u'AG'
(Pdb) p object.COMU_DESCR
None
(Pdb) p object.comu_regio
None
(Pdb) p object.NAZIONE
None
Some explanations:
- COMU_COD is the primary key of the row going in error
- COMU_PROV is a 2 characters province code
- COMU_DESCR is the field whose value includes an accented letter for this
row
the other 2 fields following in the database have not-null values with
ASCII-only characters.
All the data in the database appear ok from the MySql Administrator tool.
==========.
Some configuration info:
- Windows XP Service Pack 2
- python 2.4.4
- Zope 2.10.6-final
- Plone 3.1.4
- MySql 5.0.41; all tables: charset: utf8, collation: utf8_general_ci
=========
Error log:
Traceback (innermost last):
Module ZPublisher.Publish, line 119, in publish
Module ZPublisher.mapply, line 88, in mapply
Module ZPublisher.Publish, line 42, in call_object
Module Products.CMFFormController.ControllerPythonScript, line 161, in
__call__
Module Shared.DC.Scripts.Bindings, line 313, in __call__
Module Shared.DC.Scripts.Bindings, line 350, in _bindAndExec
Module Products.zdb.monkeypatch, line 61, in monkey_exec
Module Products.PythonScripts.PythonScript, line 327, in _exec
Module None, line 32, in createObject
- <ControllerPythonScript at /fulbright_db/fulbright/createObject used
for /fulbright_db/fulbright/tabelle>
- Line 32
Module Products.ATContentTypes.lib.constraintypes, line 281, in
invokeFactory
Module Products.CMFCore.PortalFolder, line 315, in invokeFactory
Module Products.CMFCore.TypesTool, line 716, in constructContent
Module Products.CMFCore.TypesTool, line 276, in constructInstance
Module Products.CMFCore.TypesTool, line 458, in _constructInstance
Module OFS.ObjectManager, line 326, in _setObject
Module zope.event, line 23, in notify
Module zope.component.event, line 26, in dispatch
Module zope.component._api, line 130, in subscribers
Module zope.component.registry, line 290, in subscribers
Module zope.interface.adapter, line 535, in subscribers
Module zope.component.event, line 33, in objectEventNotify
Module zope.component._api, line 130, in subscribers
Module zope.component.registry, line 290, in subscribers
Module zope.interface.adapter, line 535, in subscribers
Module OFS.subscribers, line 107, in dispatchObjectWillBeMovedEvent
Module zope.app.container.contained, line 181, in dispatchToSublocations
Module OFS.subscribers, line 87, in sublocations
Module collective.tin.container, line 82, in <generator expression>
Module collective.tin.container, line 108, in __getitem__
KeyError: '16578'
_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers