Error Session has no attribute '_Fixture_name"

98 views
Skip to first unread message

Jacinto Parga

unread,
Apr 28, 2022, 11:03:24 AM4/28/22
to py4web
I get this error and dont know what's up

Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/py4web/core.py", line 338, in is_valid self.__request_master_ctx__.request_ctx[self] KeyError: <py4web.core.Session object at 0xffff92415ac0> During handling of the above exception, another exception occurred: Traceback (most recent call last): 
 File "/usr/local/lib/python3.8/dist-packages/py4web/core.py", line 935, in wrapper ret = func(*func_args, **func_kwargs) 
 File "/usr/local/lib/python3.8/dist-packages/py4web/core.py", line 920, in wrapper raise context["exception"] 
 File "/usr/local/lib/python3.8/dist-packages/py4web/core.py", line 899, in wrapper context["output"] = func(*args, **kwargs) File "/home/www-data/amaster/apps/_dashboard/__init__.py", line 372, in api data = action.uses(db)(lambda: RestAPI(db, policy)( File "/usr/local/lib/python3.8/dist-packages/py4web/core.py", line 920, in wrapper raise context["exception"] 
 File "/usr/local/lib/python3.8/dist-packages/py4web/core.py", line 899, in wrapper context["output"] = func(*args, **kwargs) File "/home/www-data/amaster/apps/_dashboard/__init__.py", line 372, in <lambda> data = action.uses(db)(lambda: RestAPI(db, policy)( File "/usr/local/lib/python3.8/dist-packages/pydal/restapi.py", line 37, in wrapper data = func(*args, **kwargs) File "/usr/local/lib/python3.8/dist-packages/pydal/restapi.py", line 232, in __call__ return self.search(tablename, get_vars) 
 File "/usr/local/lib/python3.8/dist-packages/pydal/restapi.py", line 586, in search response["model"] = self.table_model(table, model_fieldnames) 
 File "/usr/local/lib/python3.8/dist-packages/pydal/restapi.py", line 270, in table_model field.default() if callable(field.default) else field.default File "/usr/local/lib/python3.8/dist-packages/py4web/utils/auth.py", line 375, in <lambda> user = lambda s=self: s.get_user().get("id") 
 File "/usr/local/lib/python3.8/dist-packages/py4web/utils/auth.py", line 440, in get_user if not self.session.is_valid(): 
 File "/usr/local/lib/python3.8/dist-packages/py4web/core.py", line 343, in is_valid self.__class__.__name, 
AttributeError: type object 'Session' has no attribute '_Fixture__name'

Massimo DiPierro

unread,
Apr 28, 2022, 11:00:34 PM4/28/22
to Jacinto Parga, py4web
Error could be better.

It says that in order to create a record need the user id of the logged in user but you are accessing auth from the dashboard app while auth is a fixture of another app and therefore is accessed incorrectly.

This happens a lot. 

Massimo

--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/py4web/7883ab0a-6156-4e18-99d6-2e9eadbd3d56n%40googlegroups.com.

Jacinto Parga

unread,
Apr 29, 2022, 4:47:08 AM4/29/22
to py4web
Thanks Massimo. 

I realise I was playing around auth_user_tag_default (I don't know where it comes from) and  auth_user_tag_groups from _dashboard so it may has caused the error.

I've seen different failures I have posted in several messages here. For instance sometimes _dahsboard does not load the apps but it does when I access from a browser with private window, the response of the resources that fail is 403, forbidden. 

The same happens with some signed urls in the same context, and then I have to get the cache empty to make it work. 

I use to storage session in database, not in cookies, don't know if it can have something to do with it.

This little errors make me be concerned about py4web stability. 


Jim Steil

unread,
May 1, 2022, 1:59:00 PM5/1/22
to py4web
Can you post some more details of the issues you're referencing?

-I've seen different failures I have posted in several messages here. For instance sometimes _dahsboard does not load the apps but it does when I access from a browser with private window, the response of the resources that fail is 403, forbidden. 
-The same happens with some signed urls in the same context, and then I have to get the cache empty to make it work.

I'm not seeing any of these issues. I'm not a dashboard user so that may explain it.  But I'd like to help figure it out if you have the time to post the details.

-Jim

Massimo

unread,
May 1, 2022, 3:20:00 PM5/1/22
to py4web
If you have an app "test" which does:
def get_default(): return session.get("default_thing_name"))
db.define_table("thing", Field("name", default=get_default))

and you access this table from the dashboard it will try access the session of the "test" app without an action.uses(fixture).
This is the cause of many problems people see.

We need to change py4web. We need to make it work like web2py where each app exposes its own appadmin and (maybe) database API.
I think we can do this in ways that are not backward incompatible.

Massimo

Massimo DiPierro

unread,
May 1, 2022, 4:12:26 PM5/1/22
to py4web
Taking a second look.

While the problem exists, there was a typo in the code that caused the error to be so terrible. I make some changes that will mitigate this a lot.

Also if you have a db.define_table("thing", Field("owner", default=get_default_owner))

You can do:

def get_default_owner():
if not session.is_valid():
        return None
return auth.user_id


Jacinto Parga

unread,
May 1, 2022, 5:21:46 PM5/1/22
to py4web

I suspect the following code

Captura de pantalla de 2022-05-01 23-06-02.png
... more code
Captura de pantalla de 2022-05-01 23-09-15.png

I suspect from the url_signer because if I remove it  then works, and the session["timestamp"] variable, because it does not fail in a private browser window.

If you want to take a look at the web application https://atletismomaster.es/mastercalc
P.S. Dont relay on the google translation of the webapp it's awful. Translate with py4web is a todo for me ;)

Thanks Jim, the other issues are explained in 

Message has been deleted

Massimo

unread,
May 15, 2022, 1:46:17 AM5/15/22
to py4web
I am missing context here. What is the problem?

Jacinto Parga

unread,
May 29, 2022, 4:09:24 AM5/29/22
to py4web
The error showed in the first message dissapeared when I stop using url_signer. But it worked wiht url_signer everytime I started a session from a private window browser.

As I used session to storage a local variable I thought that it could be modifying url_signer behaviour, so I give up using session to storage the local variable, but it didn't fix the error. 

The strage thing is that _dashboard dpes only work when I access through private window browser. I think the key is your answer: "and you access this table from the dashboard it will try access the session of the "test" app without an action.uses(fixture).
This is the cause of many problems people see."

But I still haven't found the controller that makes it fail.

Luca de Alfaro

unread,
May 29, 2022, 1:04:11 PM5/29/22
to Jacinto Parga, py4web
You need to include url_signer as the first parameter of @action.uses

--
Luca

Jacinto Parga

unread,
May 29, 2022, 4:37:16 PM5/29/22
to Luca de Alfaro, py4web
I thought that should be after session.

And url_signer.verify()? Does It have to be in any special position?

Luca de Alfaro

unread,
May 29, 2022, 5:04:21 PM5/29/22
to Jacinto Parga, py4web
Sorry I don’t know why I wrote the first parameter. It just needs to be a parameter. The first parameter in general is the template, the other fixtures are sorted according to their dependencies. 
--
Luca

Jacinto Parga

unread,
Aug 24, 2022, 11:09:10 AM8/24/22
to py4web
Reply all
Reply to author
Forward
0 new messages