Closed josejachuf closed 4 years ago
@josejachuf it's a bug in the session manager. Correct one should be the one with session manager on the entire application pipeline. Will push a fix in master branch in the next couple of days
@josejachuf should be fixed with ac7219c. Can you test it, please?
Thanks @gi0baro , the patch works fine, I have form login and socket. But now I have another problem in the submit, an error occurs.
ValueError: SELECT "users"."id", "users"."created_at", "users"."updated_at", "users"."email", "users"."password", "users"."registration_key", "users"."reset_password_key", "users"."registration_id", "users"."first_name", "users"."last_name" FROM "users" WHERE ("users"."email" = 'jose@test.com') LIMIT 1 OFFSET 0;
def with_connection_or_raise(f):
def wrap(*args, **kwargs):
if not args[0].connection:
if len(args) > 1:
raise ValueError(args[1])
raise RuntimeError('no connection available')
return f(*args, **kwargs)
return wrap
Full traceback
Traceback (most recent call last): File "/home/jose/emmett/venv38/lib/python3.8/site-packages/emmett/asgi/handlers.py", line 226, in dynamic_handler http = await self.router.dispatch() File "/home/jose/emmett/venv38/lib/python3.8/site-packages/emmett/routing/router.py", line 212, in dispatch http_cls, output = await route.dispatcher.dispatch(request, reqargs) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/emmett/routing/dispatchers.py", line 77, in dispatch rv = await self.get_response(wrapper, reqargs) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/emmett/routing/dispatchers.py", line 44, in get_response return self.response_builders[wrapper.method](await self.f(reqargs)) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/emmett/tools/auth/exposer.py", line 101, in _login rv['form'] = await self.ext.forms.login(onvalidation=_validate_form) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/emmett/forms.py", line 149, in _process self.onvalidation(self) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/emmett/tools/auth/exposer.py", line 91, in _validate_form row = self.config.models['user'].get(email=form.params.email) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/emmett/orm/models.py", line 625, in get return cls.table(kwargs) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/pydal/objects.py", line 563, in call return self._db(query).select(limitby=(0, 1), File "/home/jose/emmett/venv38/lib/python3.8/site-packages/emmett/orm/objects.py", line 333, in select return obj._runselect(*fields, *options) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/emmett/orm/objects.py", line 317, in _runselect return super(Set, self).select(fields, **options) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/pydal/objects.py", line 2210, in select return adapter.select(self.query, fields, attributes) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/pydal/adapters/sqlite.py", line 82, in select return super(SQLite, self).select(query, fields, attributes) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/pydal/adapters/base.py", line 760, in select return self._select_aux(sql, fields, attributes, colnames) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/pydal/adapters/base.py", line 716, in _select_aux rows = self._select_aux_execute(sql) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/pydal/adapters/base.py", line 710, in _select_aux_execute self.execute(sql) File "/home/jose/emmett/venv38/lib/python3.8/site-packages/pydal/adapters/init.py", line 65, in wrap raise ValueError(args[1]) ValueError: SELECT "users"."id", "users"."created_at", "users"."updated_at", "users"."email", "users"."password", "users"."registration_key", "users"."reset_password_key", "users"."registration_id", "users"."first_name", "users"."last_name" FROM "users" WHERE ("users"."email" = 'jose@test.com') LIMIT 1 OFFSET 0;
the pipelines are: #chat/__init__.py:
app.pipeline = [SessionManager.cookies('Walternate')]
auth_routes = auth.module(__name__)
# with and without auth_routes.pipeline
# auth_routes.pipeline = [db.pipe, auth.pipe]
#chat/main.py:
routes = app.module(__name__, name='routes')
routes.pipeline = [db.pipe, auth.pipe]
@josejachuf yeah, the issue is that auth module need database pipe. Now, with the actual apis is not possible to attach the auth module to an upper module or to provide a specific pipeline for it. Gonna publish a patch for it later today.
In the meantime, if you move the database pipe to the application pipeline, it should work, even if it waste connections.
Hi @gi0baro, this work fine:
In the meantime, if you move the database pipe to the application pipeline, it should work, even if it waste connections.
I want to know if I understood correctly. In this case, for each connection to the socket, is a new connection to the database created?
Hi @gi0baro, this work fine:
In the meantime, if you move the database pipe to the application pipeline, it should work, even if it waste connections.
I want to know if I understood correctly. In this case, for each connection to the socket, is a new connection to the database created?
Exactly.
@josejachuf since f50b5ae you should be able to customise the pipeline for the auth module, eg:
auth_routes = auth.module(__name__, pipeline=[db.pipe])
It will be released with 2.0.0a5
, I'm closing this.
@gi0baro thanks, this works fine.
my pipelines stayed this way:
app: [<emmett.sessions.CookieSessionPipe object at 0x7ff9110f8c10>] auth_routes: [<emmett.orm.base.DatabasePipe object at 0x7ff9110f8fd0>] routes: [<emmett.orm.base.DatabasePipe object at 0x7ff91110e730>]
I have my test app using websocket, but I have problems with pipelines.
@gi0baro as you have suggested in https://github.com/emmett-framework/emmett/issues/257, I have the sockets module separated. It is a bloggy modification
# chat/__init__.py
# chat/controllers/main.py:
# chat/controllers/main.py:
# chat/templates/chat.html:
As is the above works fine and the messages that are entered are displayed (from API tester plugin) view capture in: https://ibb.co/f1L3pCJ , but if I want to go to http://127.0.0.1:8000/auth/login I get the following error:
Now if I change in:
# chat/init.py change
app.pipeline = []
forapp.pipeline = [SessionManager.cookies('Walternate')]
form login works fine, but the socket stops working:In browser:
In terminal emmett: