Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 31 2019 16:42
    fantix commented #428
  • Jan 31 2019 14:11
    wwwjfy labeled #432
  • Jan 31 2019 14:11
    wwwjfy commented #432
  • Jan 31 2019 14:10

    wwwjfy on pyup-update-pytest-4.1.0-to-4.2.0

    (compare)

  • Jan 31 2019 14:10

    wwwjfy on master

    Update pytest from 4.1.0 to 4.2… (compare)

  • Jan 31 2019 14:10
    wwwjfy closed #431
  • Jan 31 2019 13:05
    diegoyosiura opened #432
  • Jan 31 2019 07:08
    aliyarly starred fantix/gino
  • Jan 31 2019 03:48
    coveralls commented #431
  • Jan 31 2019 03:41
    pyup-bot opened #431
  • Jan 31 2019 03:41

    fantix on pyup-update-pytest-4.1.0-to-4.2.0

    Update pytest from 4.1.0 to 4.2… (compare)

  • Jan 31 2019 03:41

    fantix on pyup-update-pytest-4.1.0-to-4.2.0

    (compare)

  • Jan 31 2019 01:55
  • Jan 30 2019 13:55

    wwwjfy on pyup-update-quart-0.6.10-to-0.7.0

    (compare)

  • Jan 30 2019 13:06

    wwwjfy on pyup-update-flake8-3.5.0-to-3.7.1

    (compare)

  • Jan 30 2019 13:06

    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)

  • Jan 30 2019 13:06
    wwwjfy closed #430
  • Jan 30 2019 13:03
    coveralls commented #430
  • Jan 30 2019 12:58
    wwwjfy synchronize #430
  • Jan 30 2019 12:58

    wwwjfy on pyup-update-flake8-3.5.0-to-3.7.1

    use latest flake8 in tests, ref… (compare)

Cobalt
@Chaostheorie_gitlab
File "/home/chaostheorie/P/boardgame-backend/venv/lib/python3.8/site-packages/starlette/routing.py", line 517, in lifespan await self.startup() File "/home/chaostheorie/P/boardgame-backend/venv/lib/python3.8/site-packages/starlette/routing.py", line 494, in startup await handler() File "/home/chaostheorie/P/boardgame-backend/app/config.py", line 52, in connect await db.gino.create_all() File "/home/chaostheorie/P/boardgame-backend/venv/lib/python3.8/site-packages/gino/schema.py", line 347, in create_all await self.create(bind=bind, tables=tables, checkfirst=checkfirst) File "/home/chaostheorie/P/boardgame-backend/venv/lib/python3.8/site-packages/gino/schema.py", line 333, in create bind = _bind_or_error(self._item) File "/home/chaostheorie/P/boardgame-backend/venv/lib/python3.8/site-packages/sqlalchemy/sql/base.py", line 676, in _bind_or_error raise exc.UnboundExecutionError(msg) sqlalchemy.exc.UnboundExecutionError: Gino object is not bound to an Engine or Connection. Execution can not proceed without a database to execute against
It worked in 1.0.0 and only complained at 1.0.1-beta
2 replies
db = Gino(app, dsn=Config.DATABASE_URL) init
Fantix King
@fantix
feels like it's a problem of the order of Starlette startup hooks
Cobalt
@Chaostheorie_gitlab
I only connect (and initMiddleware is not db realted)
DB is inited before startup hooks are run
Wait a sec I try with init_app
Same error
Is there a missed call taht I can make manually at the create_all point. by invoking the engine with with?
11 replies
Fantix King
@fantix
could u try not to use the on_startup parameter, but use the @app.on_event("startup") hook?
Lu
@ZinkLu

家境贫寒的我们使用了一台单核电脑去爬取网页

@ZinkLu that's really cute :laughing:

HAHA, thanks. I've been occupied recently. I'll continue this weeken (probably)

Fantix King
@fantix
yeah no worries, take ur time!
nichotin95
@nichotin95
Hi. Wanted to know if Gino by any chance has support for pg-queue. If not, any library that you guys are aware of for this purpose?
2 replies
Alexander Smirnov
@_smred_twitter
Hi chat,
can't find in docs how I can receive gino.ext.sanic.
Any refs please
9 replies
Alexander Smirnov
@_smred_twitter

Hi chat what I can use for similar query in gino?

SELECT project, name, COUNT(id) FROM event GROUP BY project, name

7 replies
Lu
@ZinkLu
image.png
@_smred_twitter. try db.func.count(Event.id) instead of db.func.count(id)
Alexander Smirnov
@_smred_twitter
@ZinkLu thx, this was the answer :]
nichotin95
@nichotin95
Hi folks, I'm trying to generate a query like the following using GINO/SQLAlchemy, but alas, no luck.
Can anyone help me out with this?
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');
The problem here is, temp_table" is a temporary table generated on the fly, hence no model. So I need to use the subquery as a text here, but can't find out how to generate a scalar subquery from the text.
9 replies
verdebirth
@verdebirth

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.

verdebirth
@verdebirth
The error I'm receiving is:
UninitializedError
Gino engine is not initialized.
Fantix King
@fantix
@rlundy82 where are you importing Gino from? If you're using db.init_app(), you should install gino[sanic] or gino_sanic and import Gino from gino.ext.sanic or gino_sanic.
1) Yes, connection pool will be created on server startup.
verdebirth
@verdebirth
I have gino_sanic installed and am importing using from gino.ext.sanic import Gino
Fantix King
@fantix
3) Usually you don't need to close the connections explicitly - they are returned to the pool after each request handling. But in case when your handling code would take a long time processing e.g. I/O, you may want to turn off "use_connection_for_request" (similar docs: https://python-gino.org/docs/en/1.0/reference/extensions/starlette.html#lazy-connection) or explicitly return the connection.
my following question would be, when did your code tried to access database and ended up with UninitializedError?
is it in a request handler, or somewhere at the top level of your main.py?
verdebirth
@verdebirth
It is in the request handler:
@blueprint.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')
Fantix King
@fantix
k let me try this
verdebirth
@verdebirth
I appreciate the help
Fantix King
@fantix
np
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)
this works for me
Fantix King
@fantix
I have:
gino==1.0.1
gino-sanic==0.1.0
was the request sent too soon after server start up? I know uvicorn had similar problem but it's fixed now
verdebirth
@verdebirth
I got the same versions.
One difference I know of is that I've got things broken down into other files (it's a large project), the model is in its own file, and the handler is also in its own file
I'm starting the server using: python -m MyServer.main
I also have Python 3.6.9
verdebirth
@verdebirth
Here's the full traceback
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.
verdebirth
@verdebirth

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.

verdebirth
@verdebirth
I figured it out: having db = Gino() in the main file was causing some circular imporI issues. I put it in db.py and it works.
nichotin95
@nichotin95
Anyone here knows how to use df.to_sql() with a GinoEngine.
I think Pandas supports sqlalchemy engine but passing in a GinoEngine (db.bind) doesn't help. Currently I'm using asyncpg's copy_to_table but for this I need to create the table_schema on my own.
nichotin95
@nichotin95
@fantix @wwwjfy
I'm trying to use pool_pre_ping argument as shown in the docs here, but it's throwing the following error. https://docs.sqlalchemy.org/en/13/core/pooling.html#disconnect-handling-pessimistic
'pool_pre_ping' sent to create_engine(), using configuration AsyncpgDialect/GinoEngine. Please checkthat the keyword arguments are appropriate for this combination of components.
Any help here would be appreciated. Thanks :)
2 replies
Wilson Beirigo Duarte
@wbeirigo_gitlab
Hi all. How to use pre-existing database with Gino?
6 replies
nichotin95
@nichotin95
Hi chat. I'm stuck with a usecase of mine corresponding the loaders.
So I've written down my own "ON" clause as the tables in consideration don't have and foreign-key relation. But I'm not sure how to load distinct children in the Parent using the "distinct" keyword.
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() )
This is loading the same Child instance in the parent again-and-again and I'm not sure how to use the distinct keyword here.
child_and_clause is working fine as the output is correct, justa that it is being added multiple times
nichotin95
@nichotin95
Nvm. Got this to work by creating dunder eq method in the model class
verdebirth
@verdebirth
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.
I am using the sanic ext:
from gino.ext.sanic import Gino
db = Gino()
Lu
@ZinkLu

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)