psqlpy-python / psqlpy

Asynchronous Python PostgreSQL driver written in Rust
https://psqlpy-python.github.io/
MIT License
211 stars 3 forks source link

does not handle array types #86

Open SamGrisey opened 3 hours ago

SamGrisey commented 3 hours ago

It would seem that array types are not being recognized properly. If I create a simple table:

CREATE TABLE IF NOT EXISTS test (
    id serial NOT NULL PRIMARY KEY,
    tags TEXT[]
);

then add some rows and do a

res = await transaction.fetch("SELECT * FROM test;")
return res.result()

the return res.result() line causes a crash:

pyo3_runtime.PanicException: called `Option::unwrap()` on a `None` value

The rust code looks like its expecting a postgres type "TEXT ARRAY" but the type is really "text[]". Even if I declare the table column as having type "TEXT ARRAY" instead of "TEXT[]", \d still reports it as "text[]"

EDIT: It actually works fine with the same simple table on a fresh database, there must be something different with the existing database... but the array column does indeed crash with that error with fetched on the old database, just no idea why now...

chandr-andr commented 3 hours ago

@SamGrisey Hello! Thank you very much for the issue. I’ll look into it today.

SamGrisey commented 3 hours ago

Ignore what I said above, the error seems to be with empty array values, not my old db instance. Example SQL:

CREATE TABLE IF NOT EXISTS test (
    id serial NOT NULL PRIMARY KEY,
    locked_fields text[] NOT NULL DEFAULT array[]::text[]
);

INSERT INTO test VALUES(1, '{"abc"}');
INSERT INTO test(id) VALUES(2);
INSERT INTO test VALUES(3, ARRAY[]::TEXT[]);

SELECTING all within psql terminal yields:

SELECT * FROM test;
 id | locked_fields 
----+---------------
  1 | {abc}
  2 | {}
  3 | {}
(3 rows)

so as you can see, all rows have arrays (neither are NULL), yet id 2 was auto-populated by its default value and 3 was explicitly set empty.

now on psqlpy, running SELECT * FROM test WHERE id = 1; works fine, but running SELECT * FROM test WHERE id = 2; and SELECT * FROM test WHERE id = 3; will cause that crash.

chandr-andr commented 3 hours ago

@SamGrisey Okay, I know what’s the problem here, I’ll fix it as soon as I come to my laptop

chandr-andr commented 13 minutes ago

@SamGrisey Please check new version - https://github.com/psqlpy-python/psqlpy/releases/tag/0.7.11