-
Notifications
You must be signed in to change notification settings - Fork 7
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
:only
Strategy is Broken
#12
Comments
We are also running into this issue. |
@niborg the solution I've adopted is to avoid this gem entirely for Redis. The solution I've settled on for my use case as follows:
The entire solution is maybe 10-15 lines of code including configuration. |
Hi @niborg, I appreciate your efforts on this PR. After reviewing your changes, I had a thought about another approach that might also work well, and in some ways, it might improve upon the solution. It's just an idea, and I'd love to hear your thoughts on it. Let me know what you think! require "database_cleaner/redis/deletion"
class DatabaseCleaner::Redis::Deletion
private
def keys_to_delete
only = @only.none? ? @connection.keys : expand_keys(@only)
except = expand_keys(@except)
(only - except)
end
end |
Hi @satoruk that solution is fine, and I support it if you want to proceed with it (it is less code, which is attractive!). However, it is worth considering the my rationale as set forth in the PR:
Your solution leaves a bit of an awkward API. For example, But in short, please go with whatever solution you prefer. I'd happily use either approach. |
During test runs I namespace all Redis operations under
"test:*
using the redis-namespace Gem. Let's check to see if it works if I configureonly: ["test*"]
:Uh oh! We've accidentally wiped every single key in the Redis DB. This is a bummer for my development environment.
I've tracked this down to this bit of code:
database_cleaner-redis/lib/database_cleaner/redis/deletion.rb
Lines 26 to 29 in e8389c2
"test:*"
namespace as expected. Ergoonly == []
except:
isn't configured, ergoexcept == []
only.none?
istrue
, therefore we go ahead and find all keys in the Redis DB (bug!!)(only - except)
returns every single key in the Redis DB, and they're then dutifully wiped outA reproduction PR: #13
I was hoping we could simply drop L28 but it seems like there's existing behaviour that relies upon this logic.
The text was updated successfully, but these errors were encountered: