question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot compile DropTable and CreateTable queries

See original GitHub issue

Hello!

I try to create table via this code:

import asyncio

from asyncpgsa import pg
import sqlalchemy as sa
from sqlalchemy.sql.ddl import CreateTable, DropTable

users = sa.Table(
    'users', sa.MetaData(),
    sa.Column('id', sa.Integer, primary_key=True),
    sa.Column('name', sa.VARCHAR(255)),
)


async def main():
    await pg.init('postgresql://localhost/test')
    await pg.query(DropTable(users))
    await pg.query(CreateTable(users))


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

and got an error from asyncpgsa

Traceback (most recent call last):
  File "/project/main.py", line 20, in <module>
    loop.run_until_complete(main())
  File "/project/.venv/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "/project/main.py", line 15, in main
    await pg.query(DropTable(users))
  File "/project/.venv/lib/python3.6/site-packages/asyncpgsa/pgsingleton.py", line 65, in query
    compiled_q, compiled_args = compile_query(query)
  File "/project/.venv/lib/python3.6/site-packages/asyncpgsa/connection.py", line 60, in compile_query
    compiled_params = sorted(compiled.params.items())
AttributeError: 'NoneType' object has no attribute 'items'

Same code using sqlalchemy works fine:

import sqlalchemy as sa
from sqlalchemy.sql.ddl import CreateTable, DropTable

users = sa.Table(
    'users', sa.MetaData(),
    sa.Column('id', sa.Integer, primary_key=True),
    sa.Column('name', sa.VARCHAR(255)),
)

engine = sa.create_engine('postgresql://localhost/test')
engine.execute(DropTable(users))
engine.execute(CreateTable(users))

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nhumrichcommented, Oct 5, 2018

This has been merged and is in version 0.25.0

1reaction
denisdubovitskiycommented, Oct 4, 2018

@nhumrich yeah, I’ve taken a closer look to the code of connection.py and decided to create my first GitHub PR 😉 #94 Please take a look at that

This PR is related to the following issue https://github.com/CanopyTax/asyncpgsa/issues/59

Read more comments on GitHub >

github_iconTop Results From Across the Web

Drop table, then cannot recreate table with the same name
You can't drop and create the same table in the same batch in sql server see MSDN. Their examples use GO to break...
Read more >
SQL DROP TABLE statement overview
This article explores SQL DROP TABLE statement for dropping SQL Server table along with various use cases.
Read more >
Can't create a table with the same name I deleted before
1 - Create table table_nome · 2 - Drop table table_nome · 3 - I'm trying to create a table with the same...
Read more >
How to Use Create Table, Alter Table, and Drop Table in ...
An introduction to the create table, alter table, and drop table commands in Oracle Database. Use these to create, change, and remove ...
Read more >
The Ultimate Guide to SQL Server DROP TABLE Statement
This tutorial shows you how to use the SQL Server DROP TABLE statement to remove one or more tables from a database.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found