I am trying to use versioning in an authenticated section of a
website. Instead of this:
db.define_table('my_table',
Field('saved_by',auth.user,
default=auth.user_id,update=auth.user_id,writable=False)
I was trying this:
db.define_table('my_table',
Field('saved_by','string',
default=auth.user.username,update=auth.user.username, writable=False)
Whenever I try to visit the website's home page (as an
unauthenticated user) web2py chokes on the table definition in models/
db.py. See below for the traceback.
Any idea how to solve this?
Maybe I should use a decorator with the define_table statement?
Regards, Andreas
[email protected]
------------------------------------------------------------------------------
Error traceback
1.
2.
3.
4.
5.
6.
7.
Traceback (most recent call last):
File "D:\Home\web\web2py\gluon\restricted.py", line 188, in
restricted
exec ccode in environment
File "D:/Home/web/web2py/applications/invest/models/db.py", line
159, in <module>
Field('change_user', 'string', default=auth.user.username,
update=auth.user.username, writable=False),
AttributeError: 'NoneType' object has no attribute 'username'
Error snapshot
Detailed traceback description
* Exception: <type 'exceptions.AttributeError'>('NoneType' object
has no attribute 'username')
Exception instance attributes
o args: ("'NoneType' object has no attribute 'username'",)
o __setattr__: <method-wrapper '__setattr__' of
exceptions.AttributeError object>
o __reduce_ex__: <built-in method __reduce_ex__ of
exceptions.AttributeError object>
o __getslice__: <method-wrapper '__getslice__' of
exceptions.AttributeError object>
o __getitem__: <method-wrapper '__getitem__' of
exceptions.AttributeError object>
o __setstate__: <built-in method __setstate__ of
exceptions.AttributeError object>
o __getattribute__: <method-wrapper '__getattribute__' of
exceptions.AttributeError object>
o __str__: <method-wrapper '__str__' of
exceptions.AttributeError object>
o __format__: <built-in method __format__ of
exceptions.AttributeError object>
o __reduce__: <built-in method __reduce__ of
exceptions.AttributeError object>
o __class__: <type 'exceptions.AttributeError'>
o __dict__: {}
o __delattr__: <method-wrapper '__delattr__' of
exceptions.AttributeError object>
o __subclasshook__: <built-in method __subclasshook__ of
type object>
o __repr__: <method-wrapper '__repr__' of
exceptions.AttributeError object>
o __init__: <method-wrapper '__init__' of
exceptions.AttributeError object>
o __hash__: <method-wrapper '__hash__' of
exceptions.AttributeError object>
o __sizeof__: <built-in method __sizeof__ of
exceptions.AttributeError object>
o __doc__: 'Attribute not found.'
o __unicode__: <built-in method __unicode__ of
exceptions.AttributeError object>
o __new__: <built-in method __new__ of type object>
* Python 2.6.5: C:\Program Files\Apache2.2\bin\httpd.exe
File D:\Home\web\web2py\gluon\restricted.py in restricted at line 188
[ code | arguments | variables ]
Function argument list: (code='# coding: utf8\n\nimport datetime as dt
\n\n#########...ail),\n db.email)\n \n', environment={'A': <class
'gluon.html.A'>, 'Auth': <class 'gluon.tools.Auth'>, 'B': <class
'gluon.html.B'>, 'BEAUTIFY': <class 'gluon.html.BEAUTIFY'>, 'BODY':
<class 'gluon.html.BODY'>, 'BR': <class 'gluon.html.BR'>, 'CENTER':
<class 'gluon.html.CENTER'>, 'CLEANUP': <class
'gluon.validators.CLEANUP'>, 'CODE': <class 'gluon.html.CODE'>,
'CRYPT': <class 'gluon.validators.CRYPT'>, ...}, layer=r'D:\Home\web
\web2py\applications\invest/models/db.py')
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
if type(code) == types.CodeType:
ccode = code
else:
ccode = compile2(code,layer)
exec ccode in environment
except HTTP:
raise
except Exception:
# XXX Show exception in Wing IDE if running in debugger
* environment: {'A': <class 'gluon.html.A'>, 'Auth': <class
'gluon.tools.Auth'>, 'B': <class 'gluon.html.B'>, 'BEAUTIFY': <class
'gluon.html.BEAUTIFY'>, 'BODY': <class 'gluon.html.BODY'>, 'BR':
<class 'gluon.html.BR'>, 'CENTER': <class 'gluon.html.CENTER'>,
'CLEANUP': <class 'gluon.validators.CLEANUP'>, 'CODE': <class
'gluon.html.CODE'>, 'CRYPT': <class 'gluon.validators.CRYPT'>, ...}
* ccode: <code object <module> at 03DB9BA8, file "D:\Home...web2py
\applications\invest/models/db.py", line 3>
File D:\Home\web\web2py\applications\invest\models\db.py in <module>
at line 159
[ code | arguments | variables ]
Function argument list: ()
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
db.define_table('email',
Field('email', 'string', length=40, notnull=False,
unique=True, represent=lambda s: s),
Field('active', 'boolean', default=True),
Field('expires', 'date', default=None,
represent=lambda s: s or 'Never'),
Field('change_user', 'string', default=auth.user.username,
update=auth.user.username, writable=False),
Field('change_date', 'datetime', default=request.now,
update=request.now, writable=False),
)
db.define_table('email_archive',
* default: undefined
* Field: <class 'gluon.sql.Field'>
* auth.username: undefined
* auth: <gluon.tools.Auth object>