Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'DAL' object has no attribute #1266

Closed
butsyk opened this issue Apr 6, 2016 · 9 comments
Closed

AttributeError: 'DAL' object has no attribute #1266

butsyk opened this issue Apr 6, 2016 · 9 comments

Comments

@butsyk
Copy link

butsyk commented Apr 6, 2016

Hello,

web2py: Version 2.14.3-stable+timestamp.2016.03.26.23.02.02
dal: 16.03

I've just updated to the last version and received the bug:
(previous version worked fine)

Table - page
Field('name', notnull=True),
Field('parent', 'integer', default=0, requires=IS_EMPTY_OR(IS_IN_DB(self.db, 'page.id', '%(name)s')),

AttributeError: 'DAL' object has no attribute 'page'

@leonelcamara
Copy link
Collaborator

Shouldn't parent be "reference page", not integer, and not have a default value at all?

Anyway it does seem like a DAL bug since page is indeed defined.

@BMarvi
Copy link
Contributor

BMarvi commented Apr 12, 2016

same here!
upgrading from 2.12.3 to 2.14.3 broke compatibility with my application.
Tried all versions so found out that last good versions was 2.13.4 and first broken is 2.14.1

My exact error:
AttributeError: 'DAL' object has no attribute 'trunks'

my relevant db.py sections:

db  = DAL('mysql://user:password@192.168.1.111/dbname',  pool_size=myconf.take('db.pool_size', cast=int), check_reserved=['mysql'],lazy_tables = True,
db.define_table('sedi',
                Field('name',            length=100, requires=IS_NOT_EMPTY()),
                Field('dominio',         'reference domini', writable=False, readable=False, default=lambda:session.domain ),
                Field('dipartimento',    'reference dipartimenti'),
                Field('trunk',           'reference trunks', ondelete='SET NULL', requires=IS_EMPTY_OR(IS_IN_DB(db, 'trunks.id','%(id)s - %(name)s'))),
                format='%(name)s',
                common_filter = lambda query: db.sedi.dominio==session.domain,
                )
db.define_table('trunks',
                Field('dominio',            'reference domini', writable=False, readable=False, default=lambda:session.domain ),
                Field('name',               length = 100, requires=IS_NOT_EMPTY()),
                Field('enabled',            'boolean', default = False),
                format='%(name)s',
                common_filter = lambda query: db.trunks.dominio == session.domain,
                )

@BMarvi
Copy link
Contributor

BMarvi commented Apr 12, 2016

Tried to isolate the problematic file.
Seems to be gluon/validators.py
Butsyk, try to downgrade just that file with the 2.13.4 version one.

@BuhtigithuB
Copy link
Contributor

trunks should maybe come before sedi??

On Tue, Apr 12, 2016 at 9:04 AM, Marvi notifications@github.com wrote:

same here!
upgrading from 2.12.3 to 2.14.3 broke compatibility with my application.
Tried all versions so found out that last good versions was 2.13.4 and
first broken is 2.14.1

My exact error:
AttributeError: 'DAL' object has no attribute 'trunks'

my relevant db.py sections:

db = DAL('mysql://user:password@192.168.1.111/dbname', pool_size=myconf.take('db.pool_size', cast=int), check_reserved=['mysql'],lazy_tables = True,
db.define_table('sedi',
Field('name', length=100, requires=IS_NOT_EMPTY()),
Field('dominio', 'reference domini', writable=False, readable=False, default=lambda:session.domain ),
Field('dipartimento', 'reference dipartimenti'),
Field('trunk', 'reference trunks', ondelete='SET NULL', requires=IS_EMPTY_OR(IS_IN_DB(db, 'trunks.id','%(id)s - %(name)s'))),
format='%(name)s',
common_filter = lambda query: db.sedi.dominio==session.domain,
)
db.define_table('trunks',
Field('dominio', 'reference domini', writable=False, readable=False, default=lambda:session.domain ),
Field('name', length = 100, requires=IS_NOT_EMPTY()),
Field('enabled', 'boolean', default = False),
format='%(name)s',
common_filter = lambda query: db.trunks.dominio == session.domain,
)


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#1266 (comment)

@BMarvi
Copy link
Contributor

BMarvi commented Apr 12, 2016

In this simple case would resolve the problem. But the complete application has many other tables and relations in a way that at least one relation must come before the table that refers to.
With the parameter lazy_tables = True would not be an issue, until version 2.14.1....

@leonelcamara
Copy link
Collaborator

Yes apparently IS_IN_DB stopped being lazy when evaluating the field. I'm looking at it, this issue is very easy to reproduce. Just put this pretty commonly used table in your db.py

db.define_table('category',
    Field('parent_id', 'reference category', requires=IS_EMPTY_OR(IS_IN_DB(db, 'category.id', '%(name)s'))),
    Field('name')
)

@BuhtigithuB
Copy link
Contributor

I think it can come from 2.13.4, I remember having noticed something
strange when try using a old app removing migrate=False... It may come from
earlier version since I use to set migrate=False since a long time...

On Wed, Apr 13, 2016 at 7:41 PM, Leonel Câmara notifications@github.com
wrote:

Yes apparently IS_IN_DB stopped being lazy when evaluating the field. I'm
looking at it, this issue is very easy to reproduce. Just put this pretty
commonly used table in your db.py

db.define_table('category',
Field('parent_id', 'reference category', requires=IS_EMPTY_OR(IS_IN_DB(db, 'category.id', '%(name)s'))),
Field('name')
)


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#1266 (comment)

@leonelcamara
Copy link
Collaborator

I have a fix for it, let me just add a test for it to make sure it doesn't happen again.

@leonelcamara
Copy link
Collaborator

@butsyk @BMarvi done, thanks for reporting the issue. Here's the pull request with the fix #1293

mdipierro added a commit that referenced this issue Apr 14, 2016
fixes #1266 and adds tests to make sure it doesn't happen again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants