View filter cannot be removed after set initially #2241

Closed
opened 2024-03-29 16:32:18 +00:00 by waza-ari · 3 comments
Contributor

Description

When a filter is set for a view, and later on the user tries to remove the filter, it doesn't work. The frontend does send a POST request to the backend containing an empty string for Filter, it is however not changed in the backend.

JSON Request POST https://try.vikunja.io/api/v1/projects/17/views/309:

{"max_right":null,"id":309,"title":"List","project_id":17,"view_kind":"list","filter":"","position":100,"bucket_configuration":[],"bucket_configuration_mode":"none","default_bucket_id":0,"done_bucket_id":0,"created":"2024-03-29T17:27:37+01:00","updated":"2024-03-29T17:28:09.505281229+01:00"}

JSON Response doesn't contain the filter:

{"id":309,"title":"List","project_id":17,"view_kind":"list","filter":"","position":100,"bucket_configuration_mode":"none","bucket_configuration":[],"default_bucket_id":0,"done_bucket_id":0,"updated":"2024-03-29T17:28:33.955186554+01:00","created":"2024-03-29T17:27:37+01:00"}

Reload the page, fetching the projects does contain the filter again GET https://try.vikunja.io/api/v1/projects/17

{"id":17,"title":"WA Test","description":"","identifier":"","hex_color":"","parent_project_id":0,"owner":{"id":1,"name":"lorem","username":"demo","created":"2021-05-30T10:45:25+02:00","updated":"2024-03-29T17:26:18+01:00"},"is_archived":false,"background_information":null,"background_blur_hash":"","is_favorite":false,"position":1114112,"views":[{"id":309,"title":"List","project_id":17,"view_kind":"list","filter":"done = true","position":100,"bucket_configuration_mode":"none","bucket_configuration":null,"default_bucket_id":0,"done_bucket_id":0,"updated":"2024-03-29T17:28:33+01:00","created":"2024-03-29T17:27:37+01:00"},{"id":310,"title":"Gantt","project_id":17,"view_kind":"gantt","filter":"","position":200,"bucket_configuration_mode":"none","bucket_configuration":null,"default_bucket_id":0,"done_bucket_id":0,"updated":"2024-03-29T17:27:37+01:00","created":"2024-03-29T17:27:37+01:00"},{"id":311,"title":"Table","project_id":17,"view_kind":"table","filter":"","position":300,"bucket_configuration_mode":"none","bucket_configuration":null,"default_bucket_id":0,"done_bucket_id":0,"updated":"2024-03-29T17:27:37+01:00","created":"2024-03-29T17:27:37+01:00"},{"id":312,"title":"Kanban","project_id":17,"view_kind":"kanban","filter":"","position":400,"bucket_configuration_mode":"manual","bucket_configuration":null,"default_bucket_id":0,"done_bucket_id":0,"updated":"2024-03-29T17:27:37+01:00","created":"2024-03-29T17:27:37+01:00"}],"created":"2024-03-29T17:27:37+01:00","updated":"2024-03-29T17:27:48+01:00"}

Vikunja Version

unstable

Browser and version

No response

Can you reproduce the bug on the Vikunja demo site?

Yes

Screenshots

No response

### Description When a filter is set for a view, and later on the user tries to remove the filter, it doesn't work. The frontend does send a POST request to the backend containing an empty string for Filter, it is however not changed in the backend. JSON Request `POST https://try.vikunja.io/api/v1/projects/17/views/309`: ```json {"max_right":null,"id":309,"title":"List","project_id":17,"view_kind":"list","filter":"","position":100,"bucket_configuration":[],"bucket_configuration_mode":"none","default_bucket_id":0,"done_bucket_id":0,"created":"2024-03-29T17:27:37+01:00","updated":"2024-03-29T17:28:09.505281229+01:00"} ``` JSON Response doesn't contain the filter: ```json {"id":309,"title":"List","project_id":17,"view_kind":"list","filter":"","position":100,"bucket_configuration_mode":"none","bucket_configuration":[],"default_bucket_id":0,"done_bucket_id":0,"updated":"2024-03-29T17:28:33.955186554+01:00","created":"2024-03-29T17:27:37+01:00"} ``` Reload the page, fetching the projects does contain the filter again `GET https://try.vikunja.io/api/v1/projects/17` ```json {"id":17,"title":"WA Test","description":"","identifier":"","hex_color":"","parent_project_id":0,"owner":{"id":1,"name":"lorem","username":"demo","created":"2021-05-30T10:45:25+02:00","updated":"2024-03-29T17:26:18+01:00"},"is_archived":false,"background_information":null,"background_blur_hash":"","is_favorite":false,"position":1114112,"views":[{"id":309,"title":"List","project_id":17,"view_kind":"list","filter":"done = true","position":100,"bucket_configuration_mode":"none","bucket_configuration":null,"default_bucket_id":0,"done_bucket_id":0,"updated":"2024-03-29T17:28:33+01:00","created":"2024-03-29T17:27:37+01:00"},{"id":310,"title":"Gantt","project_id":17,"view_kind":"gantt","filter":"","position":200,"bucket_configuration_mode":"none","bucket_configuration":null,"default_bucket_id":0,"done_bucket_id":0,"updated":"2024-03-29T17:27:37+01:00","created":"2024-03-29T17:27:37+01:00"},{"id":311,"title":"Table","project_id":17,"view_kind":"table","filter":"","position":300,"bucket_configuration_mode":"none","bucket_configuration":null,"default_bucket_id":0,"done_bucket_id":0,"updated":"2024-03-29T17:27:37+01:00","created":"2024-03-29T17:27:37+01:00"},{"id":312,"title":"Kanban","project_id":17,"view_kind":"kanban","filter":"","position":400,"bucket_configuration_mode":"manual","bucket_configuration":null,"default_bucket_id":0,"done_bucket_id":0,"updated":"2024-03-29T17:27:37+01:00","created":"2024-03-29T17:27:37+01:00"}],"created":"2024-03-29T17:27:37+01:00","updated":"2024-03-29T17:27:48+01:00"} ``` ### Vikunja Version unstable ### Browser and version _No response_ ### Can you reproduce the bug on the Vikunja demo site? Yes ### Screenshots _No response_
waza-ari added the
kind/bug
label 2024-03-29 16:32:19 +00:00
Author
Contributor

The filter is set to an empty string correctly during in the POST, however it doesn't get updated:

2024-03-29T17:45:52.241544+01:00: DEBUG ▶ models/Update 10e Updating project view. Filter value is:
2024-03-29T17:45:52.241913+01:00: DEBUG ▶ models/Update 10f 
2024-03-29T17:45:52.248261+01:00: INFO  ▶ [DATABASE] 110 [SQL] UPDATE `project_views` SET `title` = ?, `project_id` = ?, `position` = ?, `updated` = ? WHERE `id`=? [List 38 100 2024-03-29 16:45:52 145] - 6.109166ms

I don't know enough about Go to propose a fix. Somewhat related is this discussion on SO, but that's to involved for me and there may be way easier ways.

The `filter` is set to an empty string correctly during in the POST, however it doesn't get updated: ``` 2024-03-29T17:45:52.241544+01:00: DEBUG ▶ models/Update 10e Updating project view. Filter value is: 2024-03-29T17:45:52.241913+01:00: DEBUG ▶ models/Update 10f 2024-03-29T17:45:52.248261+01:00: INFO ▶ [DATABASE] 110 [SQL] UPDATE `project_views` SET `title` = ?, `project_id` = ?, `position` = ?, `updated` = ? WHERE `id`=? [List 38 100 2024-03-29 16:45:52 145] - 6.109166ms ``` I don't know enough about Go to propose a fix. Somewhat related is [this discussion](https://stackoverflow.com/questions/31048557/assigning-null-to-json-fields-instead-of-empty-strings) on SO, but that's to involved for me and there may be way easier ways.
Owner

Yeah that's because the nil value of a string is actually an empty string, Vikunja (or rather, xorm) has no way of knowing if the value was not provided or was reset. What we're doing with the other attributes (like tasks) is always requiring all fields to be provided and then telling xorm to update all fields.

Yeah that's because the nil value of a string is actually an empty string, Vikunja (or rather, xorm) has no way of knowing if the value was not provided or was reset. What we're doing with the other attributes (like tasks) is always requiring all fields to be provided and then telling xorm to update all fields.
Owner

Fixed in 89e37b88d9, please check with the next unstable build

Fixed in https://kolaente.dev/vikunja/vikunja/commit/89e37b88d9e4bfd868ef855b75ce40bd9be0733c, please check with the next unstable build
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: vikunja/vikunja#2241
No description provided.