click_house icon indicating copy to clipboard operation
click_house copied to clipboard

send_progress_in_http_headers = 1 parameter causes errors with read-only users

Open filipealc opened this issue 8 months ago • 0 comments

Problem

When using the gem with read-only ClickHouse users, queries fail because read-only users don't have permission to use the send_progress_in_http_headers parameter. This happens because the parameter is always set when the body is not empty in the Connection#get method:

https://github.com/shlima/click_house/blob/663b72d42fbcc7c6e163b6b250bc565ba343439a/lib/click_house/connection.rb#L40

Impact

This prevents using the gem with read-only ClickHouse users, as they receive permission errors when attempting to execute queries.

Suggested Solution

Make the send_progress_in_http_headers parameter configurable through the gem's configuration. This would maintain backward compatibility while allowing users to disable it when needed.

Implementation suggestion:

  1. Add a configuration option to Config class:
class Config
  # ... existing attributes ...
  attr_accessor :send_progress_in_http_headers
  
  def initialize
    # ... existing initialization ...
    @send_progress_in_http_headers = true # Default to current behavior
  end
end
  1. Modify the get method in Connection class:
def get(path = '/', body: '', query: {}, database: config.database)
  # ... existing code ...

  transport.get(path) do |conn|
    conn.params = query.merge(database: database).compact
    # Only set the parameter if configured to do so and body is not empty
    if !body.empty? && config.send_progress_in_http_headers
      conn.params[:send_progress_in_http_headers] = 1
    end
    conn.body = body
  end
end
  1. Users could then configure this option:
ClickHouse.config do |config|
  # ... other configuration ...
  config.send_progress_in_http_headers = false # Disable for read-only users
end

This approach would maintain backward compatibility while solving the issue for users working with read-only ClickHouse accounts.

filipealc avatar Apr 26 '25 00:04 filipealc