wwwjfy on pyup-update-pytest-4.1.0-to-4.2.0
wwwjfy on master
Update pytest from 4.1.0 to 4.2… (compare)
fantix on pyup-update-pytest-4.1.0-to-4.2.0
Update pytest from 4.1.0 to 4.2… (compare)
fantix on pyup-update-pytest-4.1.0-to-4.2.0
wwwjfy on pyup-update-quart-0.6.10-to-0.7.0
wwwjfy on pyup-update-flake8-3.5.0-to-3.7.1
wwwjfy on master
Update flake8 from 3.5.0 to 3.7… use latest flake8 in tests, ref… Merge pull request #430 from fa… (compare)
wwwjfy on pyup-update-flake8-3.5.0-to-3.7.1
use latest flake8 in tests, ref… (compare)
with
?
db.func.count(Event.id)
instead of db.func.count(id)
INSERT INTO raw_files (run_id, input_file_name, raw_data, knowledge_begin_date) VALUES(816, 'file_name', (SELECT json_agg(temp_table) FROM temp_table), '2020-06-30');
Heyo, I'm early-on building a project using Sanic and Gino. I'm using this in my main.py file:
app = Sanic(settings.SERVER_NAME)
app.config.DB_HOST = settings.DB_HOST
app.config.DB_USER = settings.DB_USER
app.config.DB_PASSWORD = settings.DB_PASSWORD
app.config.DB_DATABASE = settings.DB_DATABASE
app.config.DB_ECHO = settings.DB_ECHO
db = Gino()
db.init_app(app)
I haven't been able to establish a connection. However, when I put await db.set_bind(settings.SQL_DRIVER)
in a handler the connection gets established.
I have a few questions:
1) Should db.init_app(app)
be establishing a connection on its own?
2) if not, what's the preferred way to establish a connection? Middleware?
3) Should I be closing these connections when I'm done with them?
4) Am I missing anything glaringly obvious?
All help is greatly appreciated. I've been stuck on this for a while.
UninitializedError
?
main.py
?
from sanic import Sanic
from gino.ext.sanic import Gino
app = Sanic("app name")
app.config.DB_HOST = "127.0.0.1"
app.config.DB_USER = "fantixking"
db = Gino()
db.init_app(app)
class InfoModel(db.Model):
__tablename__ = "infomodel"
@app.route("/test")
async def test(request):
info = await InfoModel.query.gino.first()
ret = 'INFO MODEL domain: %s' % info.domain
return HTTPResponse(ret, content_type='text/html')
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
python -m MyServer.main
Traceback (most recent call last):
File "####/env/lib/python3.6/site-packages/sanic/app.py", line 976, in handle_request
response = await response
File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
return self.gen.send(None)
File "####/project/handlers.py", line 12, in test
info = await InfoModel.query.gino.first()
File "/usr/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
return self.gen.send(None)
File "####/env/lib/python3.6/site-packages/gino/api.py", line 137, in first
return await self._query.bind.first(self._query, *multiparams, **params)
File "####/env/lib/python3.6/site-packages/gino/api.py", line 544, in __getattribute__
raise self._exception
gino.exceptions.UninitializedError: Gino engine is not initialized.
This issue has something to do with the files being split up. I used your example and incrementally added my configs, and whatnot. It started going wrong as soon as I put the handler in it's own file.
I have 2 identical (save for the path) handlers: one on the test.py file and one in a module's handlers.py file. The one on test.py works fine.
'pool_pre_ping' sent to create_engine(), using configuration AsyncpgDialect/GinoEngine. Please checkthat the keyword arguments are appropriate for this combination of components.
loader = Parent.load(add_child=Childern.on(child_and_clause))
result = (
await loader.query.where(Parent.id == parent_id)
.where(Parent.knowledge_end_date == None)
.gino.first()
)
child_and_clause
is working fine as the output is correct, justa that it is being added multiple times
from gino.ext.sanic import Gino
db = Gino()
I'm using Gino inside my Celery apps using this line
async with db.with_bind(settings.SQL_DRIVER, echo=False) as engine:
For some reason I can't get echo to turn off.
Hi! @rlundy82. I came across the same issue while using uvicorn with Sanic+Gino. the easiest way to disable db echo is to set a higher logging level to gino_logger:
import logging
logging.getLogger("gino").setLevel(logging.WARNING)
create_user()
instead of User.create()
User.create
method