I tried not recreating the DAL object but got the error : DAL has no
attribute: 'definition'

On Sun, 22 Apr 2018, 18:31 Anthony <[email protected]> wrote:

> Hard to say for sure without seeing the code for the definition()
> function, but presumably the reference() function is being called more than
> once -- every time after the first, it is attempting to redefine a table
> that has already been defined (which is not allowed unless you set
> redefine=True).
>
> Also, there is no reason to keep recreating the DAL object (and if you are
> going to do that, there is no reason to keep adding it to current, as you
> are not using the object added to current but simply creating a new object
> in each module). Just create the DAL object once in a model file and add it
> to current there.
>
> Actually, a better approach may be to just make the db object an argument
> of the functions that use it, which will make everything more explicit:
>
> define = definition(db)
>
> Anthony
>
> On Sunday, April 22, 2018 at 11:08:05 AM UTC-4, Maurice Waka wrote:
>>
>> I have a module that imports another that reads a db as follows:
>>
>> from gluon import current
>> from pydal import DAL, Field
>> from unidecode import unidecode
>> from applications.Hestque_Wellness.modules.Hestquewell.q_refs import
>> definition
>> db = DAL('sqlite://storage.sqlite')
>> current.db = db
>> define = definition()
>>
>>
>> The imported module is as follows:
>>
>> from gluon import current
>> from pydal import DAL, Field
>> db = DAL('sqlite://storage.sqlite')
>> current.db = db
>>
>>
>> def reference():
>>     db = current.db
>>     db.define_table('definition', Field('definition'), migrate=False)
>>     rows = db(db.definition).select()
>>     for row in rows:
>>         return row.definition
>>
>> I keep getting this error:
>>
>>     definition = definition()
>>   File "applications/Hestque_Wellness/modules/Hestquewell/q_refs.py", line 
>> 321, in definition
>>     db.define_table('definition', Field('definition'), migrate=False)
>>   File "/usr/local/lib/python2.7/dist-packages/pydal/base.py", line 571, in 
>> define_table
>>     raise SyntaxError('table already defined: %s' % tablename)
>> SyntaxError: table already defined: definition
>>
>> what could be the problem?
>>
>>
>> Kind regards
>>
>> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/7xCGTfc6xAA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to