Skip to content
New issue

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

By clicking “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? Sign in to your account

Bug with prepared_statements: false and read_multi #184

Closed
ollym opened this issue Jul 1, 2024 · 0 comments · Fixed by #185
Closed

Bug with prepared_statements: false and read_multi #184

ollym opened this issue Jul 1, 2024 · 0 comments · Fixed by #185

Comments

@ollym
Copy link
Contributor

ollym commented Jul 1, 2024

Works as you would expect:

Rails.cache.write('foo', 'bar')
Rails.cache.read_multi('foo') # => {"foo"=>"bar"}

But this does not:

SolidCache::Record.connection.unprepared_statement do
  Rails.cache.write('foo', 'bar')
  Rails.cache.read_multi('foo') # => {}
end

Looking at the SQL logs. This is with prepared statements:

SolidCache::Entry Upsert (0.7ms)  INSERT INTO "solid_cache_entries" ("key","value","key_hash","byte_size","created_at") VALUES ('\x646576656c6f706d656e743a666f6f', '\x0004085b06492208626172063a064554', -4375748427727277429, 171, CURRENT_TIMESTAMP) ON CONFLICT ("key_hash") DO UPDATE SET "key"=excluded."key","value"=excluded."value","byte_size"=excluded."byte_size" RETURNING "id"
SolidCache::Entry Load (0.1ms)  SELECT "solid_cache_entries"."key", "solid_cache_entries"."value" FROM "solid_cache_entries" WHERE "solid_cache_entries"."key_hash" = $1  [[nil, -4375748427727277429]]

And this is without:

SolidCache::Entry Upsert (1.4ms)  INSERT INTO "solid_cache_entries" ("key","value","key_hash","byte_size","created_at") VALUES ('\x646576656c6f706d656e743a666f6f', '\x0004085b06492208626172063a064554', -4375748427727277429, 171, CURRENT_TIMESTAMP) ON CONFLICT ("key_hash") DO UPDATE SET "key"=excluded."key","value"=excluded."value","byte_size"=excluded."byte_size" RETURNING "id"
SolidCache::Entry Load (0.8ms)  SELECT "solid_cache_entries"."key", "solid_cache_entries"."value" FROM "solid_cache_entries" WHERE "solid_cache_entries"."key_hash" IN ($1, $2)  [[nil, -4375748427727277429]]

I noticed that without prepared statements WHERE "solid_cache_entries"."key_hash" IN ($1, $2) you have two bind parameters, but only pass one value. PostgreSQL is equally unhappy by that:

CleanShot 2024-07-01 at 20 56 18@2x

Resulting in the failure.

Must surely be something wrong with this line:
https://github.com/rails/solid_cache/blob/main/app/models/solid_cache/entry.rb#L119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant