Just updated same thing.  Here's the full error log for you.

------------------------Error Log-----------------------
ERROR    2010-06-30 04:31:46,888 restricted.py:143] Traceback (most
recent call last):
  File "C:\Users\Chris\Documents\Workspace\WebDev\gluon
\restricted.py", line 178, in restricted
    exec ccode in environment
  File "C:\Users\Chris\Documents\Workspace\WebDev\applications\init/
controllers/blog_division.py:add", line 115, in <module>
  File "C:\Users\Chris\Documents\Workspace\WebDev\gluon\globals.py",
line 96, in <lambda>
    self._caller = lambda f: f()
  File "C:\Users\Chris\Documents\Workspace\WebDev\applications\init/
controllers/blog_division.py:add", line 26, in add
  File "C:\Users\Chris\Documents\Workspace\WebDev\applications\init/
models/global.py", line 28, in add_permission
    id = auth.add_permission(group_id,name,table_name,record_id)
  File "C:\Users\Chris\Documents\Workspace\WebDev\gluon\tools.py",
line 2406, in add_permission
    record_id=long(record_id))
  File "C:\Users\Chris\Documents\Workspace\WebDev\gluon\contrib
\gql.py", line 281, in insert
    self._last_reference = tmp
  File "C:\Users\Chris\Documents\Workspace\WebDev\gluon\sql.py", line
1611, in __setattr__
    raise SyntaxError, 'Object exists and cannot be redefined: %s' %
key
SyntaxError: Object exists and cannot be redefined: _last_reference
--------------------------End Error Log---------------------

An explanation of what the structure looks like.

In the controller is:
def add():
    """
    Debug Function
    """
    group=db(db.auth_group.role=='admin').select()[0]
    add_permission(group.id,'access','admin')
    add_permission(group.id,'access','contact')
    redirect(URL(request.application,request.controller,'index'))

Then in global.py (a file in my models)

def add_permission(
    group_id,
    name='any',
    table_name='',
    record_id=0,
    ):
    """
    Calls auth.add_permission only if permission is new
    """

    rows = db(db.auth_permission.table_name==table_name).select()
    new=True
    for row in rows:
        if (row.group_id == group_id) &\
            (row.name == name)&\
            (row.table_name == table_name)&\
            (row.record_id == record_id):
            new=False
            id = row.id
    if new:
        id = auth.add_permission(group_id,name,table_name,record_id)
    return id

I've only this afternoon wrapped auth.add_permission in this other
function (when I noticed it allowed me to add duplicate enteries).
The error has been the same the whole time and goes away if gql.py is
reverted.  Hope that wrapper function in global.py doesn't confuse
anyone it's not part of this problem I don't believe.

On Jun 29, 5:13 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> I do not know but I made a change in trunk. Could you please try if it
> fixes the problem?
>
> On 29 Giu, 16:02, Chris S <sanders.ch...@gmail.com> wrote:
>
> > Narrowing it down.
>
> > I forgot to mention I'm running on the GAE development server right
> > now.  So the above error is likely with gql.py not sql.py.
> > I've reverted my copy of gql.py to 631:1f7ae1da46ff and the error is
> > now gone.  The problem is with Line Number 279:
>
> > ---- Original -----
> > tmp = self._tableobj(**fields)
> > tmp.put()
> > ----/Original -----
> > ---- New ------
> > tmp = self._tableobj(**fields)
> > self._last_reference = tmp
> > tmp.put()
> > ----/New ------
>
> > There it is now someone smarter than me can figure out why that line's
> > causing a problem when trying to add more than one permission in a
> > single function call.
>
> > On Jun 29, 3:27 pm, Chris S <sanders.ch...@gmail.com> wrote:
>
> > > I'm actually not sure how to set break points.  I'm using Eclipse so
> > > I'm sure there's a way but while I'm educating myself.  Here's all you
> > > should need to know if the above isn't descriptive enough.
>
> > > In db.py:
> > > auth = Auth(globals(),db)           # authentication/authorization
> > > auth.define_tables()                # creates all needed tables
>
> > > Using Appadmin
> > > -Add a user to auth_users
> > > -Create group 'admin' in auth_groups
> > > -Make the user a member of admin in auth_memberships
>
> > > In the application:
> > > def add():
> > >     """
> > >     Debug Function
> > >     """
> > >     group=db(db.auth_group.role=='admin').select()[0]
> > >     auth.add_permission(group.id,'access','mystuff')
> > >     auth.add_permission(group.id,'access','myotherstuff')
> > >     redirect(URL(request.application,request.controller,'index'))
>
> > > Call /application/controller/add
> > > In appadmin view the auth_permissions table.
> > > You should see two entries
> > > one with the group.id for Admin, access, and table of 'mystuff'.
> > > one with the group.id for Admin, access, and table of 'myotherstuff'.
>
> > > Instead you'll get the above error and only "mystuff" is added to the
> > > auth_permissions.
> > > You can comment out either line and add them one at a time with no
> > > errors.  In fact you can add the same permission several times and
> > > you'll see duplicate enteries.  You can not however, have both of the
> > > above added in a single function call.  This use to work but no longer
> > > does.  When I get some time maybe I can test which revision broke this
> > > but my guess is it's 650:7c531beb7820 with comment
> > > "self._last_reference, thanks Dave".
>
> > > Sorry I'm not more help. Wish I could just patch this but I'm still
> > > learning python/web2py and this one's a bit above me.
>
> > > On Jun 29, 3:01 pm, Yarko Tymciurak <resultsinsoftw...@gmail.com>
> > > wrote:
>
> > > > can you give a complete example necessary to reproduce?
>
> > > > Alternatively, you can debug yourself:  set a breakpoint at gluon/
> > > > tools.py::Auth:add_permission()
>
> > > > and analyze what's going on...
>
> > > > - Yarko
>
> > > > On Jun 29, 2:13 pm, Chris S <sanders.ch...@gmail.com> wrote:
>
> > > > > Crap that should read:
>
> > > > > To reproduce:
> > > > > def test():
> > > > >     auth.add_permission(id,'name','table1')
> > > > >     auth.add_permission(id,'name','table2')
> > > > > return
>
> > > > > I'm trying to assign two different permissions to the same group in a
> > > > > single function to get the error.
>
> > > > > On Jun 29, 2:11 pm, Chris S <sanders.ch...@gmail.com> wrote:
>
> > > > > > Actually, that's not exactly what's happening.
>
> > > > > > The error is produced when trying to make two calls back to back to
> > > > > > auth.add_permission().
> > > > > > Single calls still create duplicate enteries but back to back calls
> > > > > > error on the 2nd call never creating an entry.
>
> > > > > > To reproduce:
> > > > > > def test():
> > > > > >     auth.add_permission(id,'name','table1')
> > > > > >     auth.add_permission(id,'name','table1')
> > > > > > return
>
> > > > > > Either one of the above can be run by itself, but both in the same
> > > > > > controller will fail with the above error on the 2nd permission.
>
> > > > > > On Jun 29, 1:35 pm, Chris S <sanders.ch...@gmail.com> wrote:
>
> > > > > > > I think the most recent update to trunk I've found a spot in 
> > > > > > > sql.py
> > > > > > > where functionality is different though it might be intended.
>
> > > > > > > In the last stable release you could make a call:
> > > > > > > auth.add_permission(group.id,'name','table_name')
>
> > > > > > > You could do this with out first checking for it's existence 
> > > > > > > already.
> > > > > > > A new entry was created and no errors thrown.
> > > > > > > Now if you try to do the above call and that same permission is
> > > > > > > already defined you get:
> > > > > > > ----------New Error------------
> > > > > > > raise SyntaxError, 'Object exists and cannot be redefined: %s' % 
> > > > > > > key
> > > > > > > SyntaxError: Object exists and cannot be redefined: 
> > > > > > > _last_reference
> > > > > > > ----------/New Error------------
>
> > > > > > > While it's good that this points out that I wasn't checking for 
> > > > > > > these
> > > > > > > permissions before, it's bad that you find out by an error which
> > > > > > > didn't previously exist.
>
> > > > > > > I can wrap my add_permission calls in a try: block, or i could 
> > > > > > > check
> > > > > > > for the permission before adding.  But is that something that 
> > > > > > > should
> > > > > > > just be included in web2py by default?  It's how I assumed it 
> > > > > > > worked
> > > > > > > originally :)

Reply via email to