Closed dceddia closed 1 week ago
I tried patching this locally and it didn't have the effect I was hoping for! So I did some more digging.
It turns out the code is actually getting tripped up by a different increment
method, the one in active_support/cache/litecache.rb
here:
The transaction
returns a boolean where I think this should be returning the result of the increment.
I made this change which seems to solve the error, and the tests pass.
I'm not sure if setting result = amount
is the right way to go here, but there was a test failing when I initialized it with result = nil
.
def increment(key, amount = 1, options = nil)
key = key.to_s
options = merged_options(options)
result = amount
@cache.transaction do
if (value = read(key, options))
value = value.to_i + amount
write(key, value, options)
result = value
else
write(key, amount, options)
result = amount
end
end
result
end
I figure there probably should be a new test to accompany this but I wasn't sure where that would go.
Hello! I'm using Litestack in my app, mainly just Litecache right now, using it as my cache implementation in Rails.
This is being used by Rack::Attack, and it's hitting an error when a request comes in.
Digging into this a bit, it looks like Rack::Attack is calling
cache.count(...)
which actually calls intoRack::Attack::Cache
and runs this codeThe
store.increment
call returnstrue
but it looks like this code (and the caller) expect it to return a number.Looking at the SQL for this, I'm wondering if it needs a
RETURNING value
at the end?https://github.com/oldmoe/litestack/blob/f8283e97fd4cdcce768572a2b8ef77886f953f89/lib/litestack/sql/litecache.sql.yml#L73-L80