Skip to content

Handling of inet data type #211

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Closed
lelit opened this issue Oct 17, 2017 · 3 comments
Closed

Handling of inet data type #211

lelit opened this issue Oct 17, 2017 · 3 comments

Comments

@lelit
Copy link
Contributor

lelit commented Oct 17, 2017

Accordingly to the documentation when an inet value is missing the subnet it is assumed to be a single host.

When I insert such value thru asyncpg however something goes wrong, as the following script shows:

import asyncio
import asyncpg


SETUP_SQL = """\
CREATE TABLE test_inet (
  id serial not null primary key,
  address inet
)
"""

INSERT_SQL_1 = """
INSERT INTO test_inet (address)
VALUES ('192.168.1.100')
"""

INSERT_SQL_2 = """
INSERT INTO test_inet (address)
VALUES ($1)
"""

FETCH_SQL = """
SELECT address
FROM test_inet
ORDER BY id
"""

CLEANUP_SQL = """
DROP TABLE test_inet
"""

async def run():
    conn = await asyncpg.connect(user='theuser', password='thepassword',
                                 database='test', host='127.0.0.1')

    await conn.execute(SETUP_SQL)
    try:
        await conn.execute(INSERT_SQL_1)
        await conn.execute(INSERT_SQL_2, '192.168.1.100')
        result = await conn.fetch(FETCH_SQL)
        print(result)
    finally:
        await conn.execute(CLEANUP_SQL)

    await conn.close()


def main():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(run())


if __name__ == '__main__':
    main()

It emits:

[<Record address=IPv4Network('192.168.1.100/32')>, <Record address=IPv4Address('192.168.1.100')>]

Why does the second record, the one inserted using a parameter, have a different subnet?
Am I doing something wrong?

@lelit
Copy link
Contributor Author

lelit commented Oct 17, 2017

Oh, sorry, I saw #37 just now...

@lelit
Copy link
Contributor Author

lelit commented Oct 17, 2017

Another thing I'll wait 0.13 for! 😄

@elprans
Copy link
Member

elprans commented Oct 21, 2017

0.13 has been released with a fix for this.

@elprans elprans closed this as completed Oct 21, 2017
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants