You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the Chatwoot API to filter conversations, a POST request resulted in an internal server error (500). The request aimed to filter conversations by status and assignee_id, using "OR" and "AND" operators. The log revealed an ActiveRecord::StatementInvalid (PG::SyntaxError) in the construction of the SQL query, specifically a syntax error near a parenthesis. This suggests a problem in the logic of building dynamic queries based on the given parameters.
Environment: Hetzner Cloud
To Reproduce
Request:
Send a POST request to /api/v1/accounts/1/conversations/filter?page=1 in Chatwoot, with the Content-Type header set to application/json.
In the body of the request, include a payload to filter conversations by status (with values "open" or "resolved") using the "OR" operator, and by assignee_id (with the value "1") using the "AND" operator.
Notice a 500 Internal Server Error error in the response.
Check the server logs to find an ActiveRecord::StatementInvalid (PG::SyntaxError) related to a SQL syntax error.
I, [2024-04-07T10:02:29.811085 #1] INFO -- : source=rack-timeout id=738ab309-7380-456e-ba86-124da1e4af8f timeout=15000ms state=ready
I, [2024-04-07T10:02:29.811661 #1] INFO -- : [738ab309-7380-456e-ba86-124da1e4af8f] Started POST "/api/v1/accounts/1/conversations/filter?page=1" for 172.71.234.200 at 2024-04-07 10:02:29 +0000
I, [2024-04-07T10:02:29.815786 #1] INFO -- : [738ab309-7380-456e-ba86-124da1e4af8f] Processing by Api::V1::Accounts::ConversationsController#filter as JSON
I, [2024-04-07T10:02:29.815877 #1] INFO -- : [738ab309-7380-456e-ba86-124da1e4af8f] Parameters: {"payload"=>[{"attribute_key"=>"[FILTERED]", "filter_operator"=>"equal_to", "values"=>["open", "resolved"], "query_operator"=>"OR"}, {"attribute_key"=>"[FILTERED]", "filter_operator"=>"equal_to", "values"=>["1"], "query_operator"=>"AND"}], "page"=>"1", "account_id"=>"1", "conversation"=>{}}
I, [2024-04-07T10:02:29.823025 #1] INFO -- : [738ab309-7380-456e-ba86-124da1e4af8f] Completed 500 Internal Server Error in 7ms (ActiveRecord: 2.0ms | Allocations: 1944)
F, [2024-04-07T10:02:29.824361 #1] FATAL -- : [738ab309-7380-456e-ba86-124da1e4af8f]
[738ab309-7380-456e-ba86-124da1e4af8f] ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR: syntax error at or near ")"
LINE 1: ... (0,1) OR conversations.assignee_id IN ('1') AND ) AND "con...
^
):
[738ab309-7380-456e-ba86-124da1e4af8f]
[738ab309-7380-456e-ba86-124da1e4af8f] app/services/filter_service.rb:103:in `set_count_for_all_conversations'
[738ab309-7380-456e-ba86-124da1e4af8f] app/services/conversations/filter_service.rb:11:in `perform'
[738ab309-7380-456e-ba86-124da1e4af8f] app/controllers/api/v1/accounts/conversations_controller.rb:44:in `filter'
[738ab309-7380-456e-ba86-124da1e4af8f] app/controllers/concerns/switch_locale.rb:24:in `set_locale'
[738ab309-7380-456e-ba86-124da1e4af8f] app/controllers/concerns/switch_locale.rb:16:in `switch_locale_using_account_locale'
[738ab309-7380-456e-ba86-124da1e4af8f] app/controllers/concerns/request_exception_handler.rb:11:in `handle_with_exception'
[738ab309-7380-456e-ba86-124da1e4af8f] app/controllers/concerns/switch_locale.rb:24:in `set_locale'
[738ab309-7380-456e-ba86-124da1e4af8f] app/controllers/concerns/switch_locale.rb:11:in `switch_locale'
I, [2024-04-07T10:02:29.825322 #1] INFO -- : source=rack-timeout id=738ab309-7380-456e-ba86-124da1e4af8f timeout=15000ms service=14ms state=completed
Expected behavior
The expected behavior would be for the API to return a filtered list of conversations based on the criteria specified in the request (status "open" or "resolved" and assignee_id "1"), without errors, and with data corresponding to conversations that meet the applied filters.
Environment
Linux VM
Cloud Provider
Hetzner Cloud
Platform
Browser
Operating system
Debian GNU/Linux 12 (bookworm)
Browser and version
Edge
Docker (if applicable)
docker version
Client: Docker Engine - Community
Version: 24.0.7
API version: 1.43
Go version: go1.20.10
Git commit: afdd53b
Built: Thu Oct 26 09:08:02 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 24.0.7
API version: 1.43 (minimum version 1.12)
Go version: go1.20.10
Git commit: 311b9ff
Built: Thu Oct 26 09:08:02 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.26
GitCommit: 3dd1e886e55dd695541fdcd67420c2888645a495
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Describe the bug
When using the Chatwoot API to filter conversations, a POST request resulted in an internal server error (500). The request aimed to filter conversations by
status
andassignee_id
, using "OR" and "AND" operators. The log revealed anActiveRecord::StatementInvalid (PG::SyntaxError)
in the construction of the SQL query, specifically a syntax error near a parenthesis. This suggests a problem in the logic of building dynamic queries based on the given parameters.Environment: Hetzner Cloud
To Reproduce
Request:
/api/v1/accounts/1/conversations/filter?page=1
in Chatwoot, with theContent-Type
header set toapplication/json
.status
(with values "open" or "resolved") using the "OR" operator, and byassignee_id
(with the value "1") using the "AND" operator.Error:
500 Internal Server Error
error in the response.ActiveRecord::StatementInvalid (PG::SyntaxError)
related to a SQL syntax error.Expected behavior
The expected behavior would be for the API to return a filtered list of conversations based on the criteria specified in the request (status "open" or "resolved" and assignee_id "1"), without errors, and with data corresponding to conversations that meet the applied filters.
Environment
Linux VM
Cloud Provider
Hetzner Cloud
Platform
Browser
Operating system
Debian GNU/Linux 12 (bookworm)
Browser and version
Edge
Docker (if applicable)
Docker Compose version v2.21.0
Additional context
psql (PostgreSQL) 16.2 (Debian 16.2-1.pgdg120+2)
The text was updated successfully, but these errors were encountered: