Closed guillaume-alliander closed 1 year ago
What i find weird is that I can't reproduce this error running the library's test suite, which should definitely cover default grant comparison, and i can confirm that the pasted query fails in even postgres 11, which is what i'm testing with.
Your specific change, i think doesn't work because SQLAlchemy then complains about something else. I suspect literal("n").cast(CHAR).label("relkind"),
should work, but i'd really like to see it fail in the test-suite
Aha. So the buried lede here was that you're using psycopg
(i.e. psycopg3) rather than psycopg2
or asyncpg
. This seems to emit a bunch of additional casts which aren't apparent when using the other options.
The fix should be relatively simple, I'm mostly trying to figure out CI to ensure general compatibility
Indeed, I am using psycopg
! And your next PR looks much cleaner than mine, thanks!
psycopg
has another unfortunate (but workable around) side effect.
I have roles with an infinity validuntil (default RDS grants, I cannot change them). With psycopg2
, infinity is cast to datetime.max
. With psycopg
this raises an error when analysing the current roles: https://github.com/DanCardin/sqlalchemy-declarative-extensions/blob/main/src/sqlalchemy_declarative_extensions/dialects/postgresql/schema.py#L64
I wondered about submitting a PR which would reduce infinity to a PG date which would fit into python datetime
(this should have no side effect because this query is only used internally by
sqlalchemy-declarative-extensions), but as there is a recipe in the psycopg doc to overload the dateloader, it might not be needed, although I am now doing a global override, which might be overkill.
Anyway, this is not relevant to this PR :)
This comment ^, actually seems to have revealed a latent "bug" where we were not removing valid until
if set. Seems like "the way" to do this is by setting it to infinity
. Setting it to (or leaving it at) None
in python implies infinity/unsetness.
So our fix is going to be to coerce infinity
to None
, and treat them as the same except for unsetting.
Should be released in v0.4.4 in a few mins
Awesome, thanks for all your help!
feel free to create a new issue, if this didn't solve all the your problems, closing for now.
Hi,
I'm trying to use this library to manage grants. It works nicely for schemas and roles, but I get an error for grants.
I am basically following the example, where I eventually have in env.py (this is for use with Alembic):
When I try to autogenerate migrations, this sql query runs (with parameter substitution done for ease of trying it out):
which fails with:
The place of the error (and workaround) is indicated in the query. The same query run directly in PG gives the same error.
The traceback is:
This happens at least with postgres 13 (and postgis 3, apline) from docker and on postgres 15 (postgis 3, normal version): https://registry.hub.docker.com/r/postgis/postgis/tags?page=1&name=15-3.3 I am using sqlachemy 2.
I tried to look deeper, but that is not something it looks like I could fix.