On Friday, February 3, 2017 at 4:05:55 PM UTC-5, MarkEdson AtWork wrote:
>
> I found a similar issue with a db.py module with code like this in it...
>
> from gluon.packages.dal.pydal import DAL, Field
>     db = DAL("sqlite://storage.sqlite")
>     db.define_table(
>         "test",
>         Field("myid", default=DEFAULT_VALUE, length=15),
>         Field("name", default=DEFAULT_VALUE, length=15),
>         Field("code", default=DEFAULT_VALUE, length=2),
>      )
>
>
How are you using that module within your app?

Most likely, you should not be defining the db object at the top level of 
your module. If you do that, you will have a single db object that lives 
across all requests. The problem with that is if you dynamically change any 
attributes of any models in some requests (e.g., temporarily changing the 
default value or validator of a field), those changes will persist across 
all requests (until changed again somewhere else).

Instead, you should define the db object and its models for each request. 
If you want to keep the code in a module, put it inside of functions or 
classes and call those functions/classes from your app's model or 
controller code.

Anthony

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to