Sqlalchemy 'str' object (ColumnElement) has no attribute 'label'

I'm migrating my SQLAlchemy development from Plone 3.3.5 to Plone 5.2
Have used collective.lead and advices from Datenbankanbindungen — Plone-Entwicklerhandbuch

The transformation to z3c.sqlalchemy 1.5 seems to be ok. I get connection and session and can read metadata und tables.

The mentioned problem occur when a query is started:

place_list = session.query(Place.name.label('name'), Place.id.label('id'), Place.type.label('place_type'), Rural_District.name.label('rural_district'), Rural_District.alias.label('rural_district_alias'),

Data has been modeled via zope.schema, i.e. Place and Rural_District, as shown in Datenmodellierung — Plone-Entwicklerhandbuch

class IPlace(Interface):
id = schema.Int(title=(u"Place identifier"),
(u"A unique id for this place"),
name = schema.TextLine(title=(u"Place name"),
(u"The name for this place (last known)"),
type = schema.TextLine(title=(u"Place type"),
(u"The type of this place (last known)"),

In Plone 3.3.5 with Python 2.4 and SQLAlchemy-0.4.8 the label method has done in the way as above presented.

Now with Plone 5.2, Python 2.7 and SQLAlchemy-1.2.19 (and z3c.sqlalchemy and zope.sqlalchemy) it seems, that Place.name etc. is no longer interpreted as ColumnElement as defined in sqlalchemy/sql/elements.py but as a simple string.

E.g. Place is initialized by:
class Place(object):
id = None
name = ''
type = ''

What do I need to change, that e.g. Place.name will not be interpreted as str but as ColumnElement, or what else is the recommendation.

Regards, Fritz

For those, who may will come into same trouble.
I have changed all into declarative base, which means that zope.schema is not longer used and the mappers declaration from "Plone Entwicklerhandbuch" (see article above) is also not longer necessary.

All other python scripts for sqlalchemy can then be used as in the earlier version.

How to write the declarative base see tutorial for SQLAlchemy.

1 Like

Plone Foundation Code of Conduct