casbin / xorm-adapter

Xorm adapter for Casbin
https://github.com/casbin/casbin
Apache License 2.0
384 stars 58 forks source link

Fails to connect to pg 16.1 #61

Closed jetaggart closed 9 months ago

jetaggart commented 9 months ago

Using PG 16.1 or 15.5, the adapter fails to connect:

error: adapter: pq: trailing junk after parameter at or near "$1A"

a, err := xormadapter.NewAdapter("postgres", "dbname=dbname user=admin password=admin host=localhost port=5432 sslmode=disable", true)

OR

a, err := xormadapter.NewAdapter("postgres", "user=admin password=admin host=localhost port=5432 sslmode=disable")

Both fail. It works the first time, it will create the casbin_rule table and perform a query. The second time I boot the application I get the above error.

casbin-bot commented 9 months ago

@tangyang9464 @JalinWang @imp2002

hsluoyz commented 9 months ago

@jetaggart I can't reproduce your issue. We have unit test at:

https://github.com/casbin/xorm-adapter/blob/1089d551d1211e2450d3bebc4a7e713381442c58/adapter_test.go#L357-L387

  1. The unit test has passed in the GitHub CI:
  2. I also tested locally with my localhost postgres for multiple times, also no issue

image

image

jetaggart commented 9 months ago

Hmm very strange. I run all my local pg instances out of docker compose, maybe it's something with that. I ended up using a different adapter (database/sql) and that's working. Feel free to close if it's not reproducible.

jetaggart commented 9 months ago

Also, it worked the first time it connected. Connected and migrated just fine, subsequent connects failed to boot. Does your test connect, disconnect, then reconnect?

hsluoyz commented 9 months ago

@jetaggart I think I have, I run this test for multiple times (comment the mysql code):

https://github.com/casbin/xorm-adapter/blob/1089d551d1211e2450d3bebc4a7e713381442c58/adapter_test.go#L357-L387