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)

rlundy82
@rlundy82
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
rlundy82
@rlundy82
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
rlundy82
@rlundy82
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.
rlundy82
@rlundy82

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.

rlundy82
@rlundy82
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
rlundy82
@rlundy82
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)
nichotin95
@nichotin95
@fantix @wwwjfy Do we have sqlalchemy type events in place? (like after_create, after_update, etc.) Or is there any decent way to achieve this?
Solution provided here looks a bit hacky and I'm not very convinced if I should implement something like this (If any of you approves, I can go and implement a similar setup). Thanks :)
Fantix King
@fantix
these events are on SQLAlchemy ORM mapped objects right?
nichotin95
@nichotin95
Correct
Fantix King
@fantix
Would something like a helper function work? For example, define a create_user function to be 1) user = User.create(), and 2) user.xxx = yyy as the after_create hook
then call create_user() instead of User.create()
or alternatively override User.create method
Just my first reaction to this question, would require more use cases though
nichotin95
@nichotin95
Ohh okay, I get it. This certainly can be implemented. But any core event like creation of the table, how should one handle that?
Fantix King
@fantix
hmm "creation of the table" assumes the use of something like User.__table__.create() or db.gino.create_all()
such hooks could be added
but the create() and create_all() functions are a bit less elegant - they're copied from SQLAlchemy and manipulated to be async, so I'm overall not a big fan
nichotin95
@nichotin95
Ok. So my use case was to add a trigger right after a table is created, if the table is not created, don't do anything. I can certainly use such hooks, or write an intelligent query which checks for the presence of the trigger. Thanks for such spontaneous inputs :)
Fantix King
@fantix
oh sure
nichotin95
@nichotin95
Yeah, but currently we are not planning to add a tool like alembic in the setup as it had some limitations when I lasted tested it wit docker and kubernetes. Might add that sometime later though, after a proper understanding
Fantix King
@fantix
makes sense
the create_async or GinoSchemaVisitor.create might be the places to override
nichotin95
@nichotin95
Yeah, feels like I'm looking at the right place finally. Thanks
Fantix King
@fantix
:+1: good luck!
Dima Veselov
@dveselov
Hi guys, does anybody knows how to wrap all pytest (pytest-asyncio) + sanic/aiohttp test cases in transactions? Seems like there is multiple different event loops, and asyncpg can't work in this conditions (similar issue like I have: python-gino/gino#713)
1 reply
As alternative solution I'm already do TRUNCATE at end of each test case, but it is too slow, nearly 1 second for each test case. Transactions can improve mine test run time significally, I think.
As final solution I want have something like django test cases, where transaction starts at setup_method and rollbacks at teardown_method.
Thanks in advance.
rlundy82
@rlundy82
@ZinkLu Thanks, this worked!
ivan-pozniak
@ivan-pozniak_gitlab

Hi. May be anybody knows why sqlalchemy query execute faster then Gino query. I have this type pf code with Gino

async with db.with_bind(connecting_str) as engine:
            instructions = await Instruction.query.where(Instruction.id==int(instruction_id)
                                    ).where(Instruction.trigger_id==int(instruction['trigger_id'])).gino.first()
            await instructions.update(blocks=instruction['blocks']).apply()

. And my SQLAlchemy code:

with AlchemySession() as db:
            db.session.query(Trigger).filter(Trigger.id == trigger_id).update({'instructions_id': request['instructions_id']})
            db.session.commit()
Aleksandr
@Aleksandr_fuze_gitlab
@ivan-pozniak_gitlab
You use 2 requests with gino (getting object then updating) and one with alchemy, only updating. Furthermore, you use different conditions on queries...
ivan-pozniak
@ivan-pozniak_gitlab
@Aleksandr_fuze_gitlab How can I update my parent table with child data like in sqlalchemy?
ivan-pozniak
@ivan-pozniak_gitlab

How can we use update query in sqlalchemy

db.session.query(Trigger).filter(Trigger.id == trigger_id).update({'instructions_id': request['instructions_id']})

style for one-to-many relations?
Shall we do it without getting foreign key and then find child table with this key and after that update this row?

2 replies
ivan-pozniak
@ivan-pozniak_gitlab
Hi! If i have gino query should i always use ayncio.sleep() in the end of the query?
1 reply