Do not save user preferences on read-only mode
What does this MR do?
Geo secondaries are in read only mode, so modifying the database in GET requests throws 500 errors.
closes #55024 (closed)
Idea for the future
We should probably add a spec to prevent this from happening.
I tried to wrap :get
method from rspec using:
module DatabaseReadOnlyCheck
def get(*)
previous_changes = changes_count
super
if previous_changes != changes_count
raise("Changes made")
end
end
def changes_count
database_name = Rails.configuration.database_configuration[Rails.env]["database"]
changes =
ActiveRecord::Base.connection.execute <<-SQL
SELECT tup_inserted, tup_updated, tup_deleted FROM pg_stat_database
WHERE datname = '#{database_name}'
SQL
changes.first
end
end
But postgres takes a while to udpate pg_stat_database
which does not fail the specs. Any idea here would be appreciated.
Edited by Felipe Cardozo