Hello ! I'm running SQLAlchemy 0.2.8 with Python 2.4.

I have the following :

roles_table = Table('roles', meta,
    Column('id', Integer, primary_key=True, nullable=False),
    Column('name', String(100), nullable=False))

users_table = Table('users', meta,
    Column('id', Integer, primary_key=True, nullable=False),
    Column('added', DateTime, nullable=False, default=func.localtimestamp),
    Column('modified', DateTime, nullable=False, 
default=func.localtimestamp, onupdate=func.localtimestamp),
    Column('first_name', String(200), nullable=False),
    Column('last_name', String(200), nullable=False),
    Column('login', String(200), nullable=False),
    Column('password', String(40), nullable=False),
    Column('email', String(200), nullable=False))

user_role_table = Table('user_role', meta,
    Column('role_id', Integer, ForeignKey('roles.id'), primary_key=True, 
nullable=False),
    Column('user_id', Integer, ForeignKey('users.id'), primary_key=True, 
nullable=False))

mapper(role.Role, roles_table)

mapper(authentication.User, users_table, properties = {
    'roles'         : relation(role.Role, secondary=user_role_table, 
cascade='all, delete-orphan'),
    '_id'           : users_table.c.id,
    '_added'        : users_table.c.added,
    '_modified'     : users_table.c.modified,
    '_first_name'   : users_table.c.first_name,
    '_last_name'    : users_table.c.last_name,
    '_login'        : users_table.c.login,
    '_password'     : users_table.c.password,
    '_email'        : users_table.c.email
})

The situation is the following:
I'm using the MVC pattern with mod_python (with a home made handler). 
BaseController is the root class for all the controllers. Every action 
is rendered through the .render() method in the BaseController.
I have a controller called UserController with a method .login() - if 
the login is successfull I store an User object (which is the 
authenticated user) in the user (mod_python) session. The problem I have 
is that when I reload the session it fail with the following error :

PythonHandler public/dispatch: Traceback (most recent call last):
PythonHandler public/dispatch:   File 
"/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in 
HandlerDispatch\n    result = object(req)
PythonHandler public/dispatch:   File 
"/home/jcigar/public_html/bbpf_website/trunk/public/dispatch.py", line 
34, in handler\n    ctrl_inst = ctrl_class(req)
PythonHandler public/dispatch:   File 
"/home/jcigar/public_html/bbpf_website/trunk/application/controllers/site.py", 
line 16, in __init__\n    super(SiteController, self).__init__(req)
PythonHandler public/dispatch:   File 
"/home/jcigar/public_html/bbpf_website/trunk/application/controllers/base.py", 
line 18, in __init__\n    self.session_user   = 
Session.DbmSession(self.req, dbm=configuration.main.SESSION_LOCATION)
PythonHandler public/dispatch:   File 
"/usr/lib/python2.4/site-packages/mod_python/Session.py", line 337, in 
__init__\n    timeout=timeout, lock=lock)
PythonHandler public/dispatch:   File 
"/usr/lib/python2.4/site-packages/mod_python/Session.py", line 166, in 
__init__\n    if self.load():
PythonHandler public/dispatch:   File 
"/usr/lib/python2.4/site-packages/mod_python/Session.py", line 225, in 
load\n    dict = self.do_load()
PythonHandler public/dispatch:   File 
"/usr/lib/python2.4/site-packages/mod_python/Session.py", line 361, in 
do_load\n    return cPickle.loads(dbm[self._sid])
PythonHandler public/dispatch:   File 
"/usr/lib/python2.4/site-packages/sqlalchemy/attributes.py", line 337, 
in __setstate__\n    self.attr = getattr(d['obj'].__class__, self.key)
PythonHandler public/dispatch: AttributeError: type object 'User' has no 
attribute 'roles'

Is it possible that the Relation() "roles" of the "User" mapper is not 
serializable .. ?

Here is my code :

import os.path

from sqlalchemy import create_session
from genshi.template import TemplateLoader
from genshi.core import Markup
from mod_python import util, Session, apache

from application.models.authentication import User, AnonymousUser

import configuration

class BaseController(object):
  
    def __init__(self, req):
        self.req            = req
        self.session_db     = create_session()
       
        # THIS IS THE LINE WHICH FAIL
        self.session_user   = Session.DbmSession(self.req, 
dbm=configuration.main.SESSION_LOCATION)
       
        self.user         = self.session_user.get('user', AnonymousUser())
        self.errors         = {}
        self.params         = {}
        self.context        = {}

        try:
           # detached -> persistent//
           self.session_db.update(self.user)
        except:
           pass

    def render(self, template):
        self.context.update(Markup=Markup, user=self.user, 
SITE_ROOT=configuration.main.SITE_ROOT, 
MEDIA_ROOT=configuration.main.MEDIA_ROOT, request=self.req, 
errors=self.errors)

        loader      = 
TemplateLoader([configuration.main.TEMPLATES_LOCATION])
        template    = loader.load(template)
        stream      = template.generate(**self.context)

        if not self.req._content_type_set:
            self.req.content_type = 'text/html;charset=UTF-8'

        self.req.write(stream.render(method='xhtml', encoding='utf-8'))

        self.session_user.save()
        self.session_db.close()

In advance thanks for answers !

Julien

-- 
Julien Cigar
Belgian Biodiversity Platform
http://www.biodiversity.be
Université Libre de Bruxelles
Campus de la Plaine CP 257
Bâtiment NO, Bureau 4 N4 115C (Niveau 4)
Boulevard du Triomphe, entrée ULB 2
B-1050 Bruxelles
office: [EMAIL PROTECTED]
home: [EMAIL PROTECTED]


--~--~---------~--~----~------------~-------~--~----~
 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to