1

I want to use DataSync on my current application, using IHP 0.16. I believe I have followed all the installation steps in FrontController and Routes.

I have a characters table with a user_id column connected to the users table. I have set the policy on the characters table resulting in this generated SQL:

CREATE POLICY "Users can manage their characters" ON characters USING (user_id = ihp_user_id()) WITH CHECK (user_id = ihp_user_id());
ALTER TABLE characters ENABLE ROW LEVEL SECURITY;

Trying to run this in the JavaScript console

await query("characters").fetch()

I get this error in JavaScript output:

enter image description here

And this error in IHP output:

Query (2.119753ms): "SELECT relrowsecurity FROM pg_class WHERE oid = ?::regclass" ["characters"]
Query (0.111442ms): "SET LOCAL ROLE ?" [Identifier {fromIdentifier = "ihp_authenticated"}]
Query (0.130888ms): "SET LOCAL rls.ihp_user_id = ?" Only {fromOnly = Just 0d7b46b1-bcb4-46a2-bf77-ad27dace8416}
FormatError {fmtMessage = "1 single '?' characters, but 3 parameters", fmtQuery = "SELECT ? FROM ??", fmtParams = ["*","characters",""]}

This seems to be another error than the row level security error in the DataSync tutorial in the IHP docs. Any idea on what causes this error?

1 Answers1

2

This is a known bug in IHP v0.16.0. It's already fixed in master

It's best to use IHP DataSync with the version mentioned in the introduction text at https://ihp.digitallyinduced.com/Guide/realtime-spas.html :)

There's btw a workaround for the bug if you don't want to upgrade: You always need to specify an order by, like await query("characters").orderBy('createdAt').fetch()

Marc Scholten
  • 1,351
  • 3
  • 5
  • Thank you! Seems like there is a different error now after doing this: ``` Query (2.099332ms): "SELECT relrowsecurity FROM pg_class WHERE oid = ?::regclass" ["characters"] Query (7.7727e-2ms): "SET LOCAL ROLE ?" [Identifier {fromIdentifier = "ihp_authenticated"}] Query (0.181584ms): "SET LOCAL rls.ihp_user_id = ?" Only {fromOnly = Just 0d7b46b1-bcb4-46a2-bf77-ad27dace8416} SqlError {sqlState = "42P01", sqlExecStatus = FatalError, sqlErrorMsg = "relation \"characters\" does not exist", sqlErrorDetail = "", sqlErrorHint = ""} ``` Updated, removed old policy and re-added polciy. – Lars Lillo Ulvestad Nov 12 '21 at 19:59
  • As commented on my question, the issue I had has now been solved by the latest IHP build. Thanks @marc-scholten ! – Lars Lillo Ulvestad Nov 12 '21 at 21:49