paulgessinger / swift-paperless

Native iOS app for interacting with a Paperless-ngx installation to manage documents
https://swift-paperless.gessinger.dev/
MIT License
235 stars 13 forks source link

Saved views are not shown when sort_field is null #108

Closed skyfmmf closed 1 month ago

skyfmmf commented 1 month ago

When I open the app, I immediately get the small popup at the top saying "❌ An unexpected error occurred" with a tap from the Taptic Engine. The popup repeats from time to time when navigating the app/settings and also when I open the share sheet of the app from a different app to import a document into swift-paperless. Additionally, I noticed that the "three bar menu" to select the saved view is empty and the list of saved views in the app is empty as well, despite having multiple saved views in my paperless instance. The logs show the following error:

[4.6.2024, 13:42] [API] Unable to decode response to https://example.com/api/saved_views/?page_size=100000 as ListResponse<SavedView> from body <private>: Error Domain=NSCocoaErrorDomain Code=4865 UserInfo={NSCodingPath=<private>, NSDebugDescription=<private>}
[4.6.2024, 13:42] [API] Error in SavedView API sequence: valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "results", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "sort_field", intValue: nil)], debugDescription: "Cannot get unkeyed decoding container -- found null value instead", underlyingError: nil))

Performing the same API requests by hand shows that the sort_field of one saved view (my Inbox view) is indeed null. The other views do have the sort_field set. I'm not sure, why my Inbox doesn't have it, but I don't recall modifying anything about that saved view, so maybe this is some default? Anyways, the JSON I get from the API looks like this:

{
  "count": 2,
  "next": null,
  "previous": null,
  "all": [
    1,
    2
  ],
  "results": [
    {
      "id": 1,
      "name": "Inbox",
      "show_on_dashboard": true,
      "show_in_sidebar": true,
      "sort_field": null,
      "sort_reverse": false,
      "filter_rules": [
        {
          "rule_type": 6,
          "value": "1"
        }
      ],
      "page_size": null,
      "display_mode": null,
      "display_fields": null,
      "owner": 3,
      "user_can_change": true
    },
    {
      "id": 2,
      "name": "To Do",
      "show_on_dashboard": true,
      "show_in_sidebar": true,
      "sort_field": "created",
      "sort_reverse": true,
      "filter_rules": [
        {
          "rule_type": 6,
          "value": "2"
        }
      ],
      "page_size": null,
      "display_mode": null,
      "display_fields": null,
      "owner": 3,
      "user_can_change": true
    }
  ]
}

Paperless-ngx seems to play well with the sort_field being null and just uses some default sort order (from the database, I assume). So I think swift-paperless should accept it as well.

paulgessinger commented 1 month ago

Thanks for reporting this @skyfmmf. This looks like an oversight in the deserialization. I'll look into it!

paulgessinger commented 1 month ago

Can you check out build 83 on TestFlight @skyfmmf?

skyfmmf commented 1 month ago

Thank you for the fast response! TestFlight only offered build 84 to me, but that has the issue fixed. No error messages and I can see all my saved views.

Also, a sincere thank you for the swift-paperless app. I really enjoy using it :)

timespaced commented 1 month ago

@paulgessinger going to add my error here because it seems related. I get the same banner error at the top with the red X “❌ Unexpected error.” Logs are different from OP but seem related.

Tested with App Store version and TestFlight version.

Logs below.

[6/5/2024, 18:22] [General] Last app version could not be read: Error Domain=NSCocoaErrorDomain Code=4865 UserInfo={NSDebugDescription=<private>, NSCodingPath=<private>}
[6/5/2024, 18:22] [General] Last app version was: ?
[6/5/2024, 18:22] [General] Current app version is: 1.3.0 (84)
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [General] Checking login status
[6/5/2024, 18:22] [API] Connection info changed, reloading!
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [API] Initializing ApiRepository with connection <private> <private>
[6/5/2024, 18:22] [API] Getting backend versions
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [API] Backend version info: API version: 5, backend version: 2.9.0
[6/5/2024, 18:22] [General] Fetch all store request
[6/5/2024, 18:22] [API] Getting document sequence for filter
[6/5/2024, 18:22] [General] Fetch all store
[6/5/2024, 18:22] [General] Fetch all store request
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [General] App becomes active
[6/5/2024, 18:22] [API] StoragePath API sequence fetch was empty
[6/5/2024, 18:22] [API] Correspondent API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] Unable to decode response to https://example.com/api/saved_views/?page_size=100000 as ListResponse<SavedView> from body {"count":1,"next":null,"previous":null,"all":[1],"results":[{"id":1,"name":"inbox","show_on_dashboard":true,"show_in_sidebar":true,"sort_field":"score","sort_reverse":false,"filter_rules":[{"rule_type":20,"value":"inbox"}],"page_size":null,"display_mode":null,"display_fields":null,"owner":3,"user_can_change":true}]}: Error Domain=NSCocoaErrorDomain Code=4864 UserInfo={NSDebugDescription=<private>, NSCodingPath=<private>}
[6/5/2024, 18:22] [API] Error in SavedView API sequence: dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "results", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "sort_field", intValue: nil)], debugDescription: "Cannot initialize SortField from invalid String value score", underlyingError: nil))
[6/5/2024, 18:22] [API] DocumentType API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] Tag API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] Caught error fetching https://example.com/api/users/?page_size=100000: Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://example.com/api/users/?page_size=100000, NSErrorFailingURLKey=https://example.com/api/users/?page_size=100000, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <E81FCA95-6D09-41D1-898B-7ACBC8C6ACDE>.<9>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <E81FCA95-6D09-41D1-898B-7ACBC8C6ACDE>.<9>, NSLocalizedDescription=cancelled}
[6/5/2024, 18:22] [API] Error in User API sequence: Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://example.com/api/users/?page_size=100000, NSErrorFailingURLKey=https://example.com/api/users/?page_size=100000, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <E81FCA95-6D09-41D1-898B-7ACBC8C6ACDE>.<9>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <E81FCA95-6D09-41D1-898B-7ACBC8C6ACDE>.<9>, NSLocalizedDescription=cancelled}
[6/5/2024, 18:22] [API] Caught error fetching https://example.com/api/ui_settings/: Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://example.com/api/ui_settings/, NSErrorFailingURLKey=https://example.com/api/ui_settings/, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <D6E89B5A-DAA8-4CCB-96F9-9CFA89B2243F>.<3>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <D6E89B5A-DAA8-4CCB-96F9-9CFA89B2243F>.<3>, NSLocalizedDescription=cancelled}
[6/5/2024, 18:22] [General] Unable to get current user: Error Domain=NSURLErrorDomain Code=-999 UserInfo={NSErrorFailingURLStringKey=<private>, NSErrorFailingURLKey=<private>, _NSURLErrorRelatedURLSessionTaskErrorKey=<private>, _NSURLErrorFailingURLSessionTaskErrorKey=<private>, NSLocalizedDescription=<private>}
[6/5/2024, 18:22] [General] Fetch all store
[6/5/2024, 18:22] [API] Document API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] Get thumbnail for document 25
[6/5/2024, 18:22] [API] Get thumbnail for document 24
[6/5/2024, 18:22] [API] Get thumbnail for document 23
[6/5/2024, 18:22] [API] Get thumbnail for document 22
[6/5/2024, 18:22] [API] Get thumbnail for document 21
[6/5/2024, 18:22] [API] Get thumbnail for document 20
[6/5/2024, 18:22] [API] Get thumbnail for document 19
[6/5/2024, 18:22] [API] Get thumbnail for document 18
[6/5/2024, 18:22] [API] Get thumbnail for document 17
[6/5/2024, 18:22] [API] Get thumbnail for document 16
[6/5/2024, 18:22] [API] Get thumbnail for document 15
[6/5/2024, 18:22] [API] Get thumbnail for document 14
[6/5/2024, 18:22] [API] Get thumbnail for document 13
[6/5/2024, 18:22] [API] Get thumbnail for document 12
[6/5/2024, 18:22] [API] Get thumbnail for document 11
[6/5/2024, 18:22] [API] Get thumbnail for document 10
[6/5/2024, 18:22] [API] Get thumbnail for document 9
[6/5/2024, 18:22] [API] Get thumbnail for document 8
[6/5/2024, 18:22] [API] Get thumbnail for document 2
[6/5/2024, 18:22] [API] Get thumbnail for document 1
[6/5/2024, 18:22] [API] Unable to decode response to https://example.com/api/saved_views/?page_size=100000 as ListResponse<SavedView> from body {"count":1,"next":null,"previous":null,"all":[1],"results":[{"id":1,"name":"inbox","show_on_dashboard":true,"show_in_sidebar":true,"sort_field":"score","sort_reverse":false,"filter_rules":[{"rule_type":20,"value":"inbox"}],"page_size":null,"display_mode":null,"display_fields":null,"owner":3,"user_can_change":true}]}: Error Domain=NSCocoaErrorDomain Code=4864 UserInfo={NSDebugDescription=<private>, NSCodingPath=<private>}
[6/5/2024, 18:22] [API] Error in SavedView API sequence: dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "results", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "sort_field", intValue: nil)], debugDescription: "Cannot initialize SortField from invalid String value score", underlyingError: nil))
[6/5/2024, 18:22] [API] Get thumbnail for document 22
[6/5/2024, 18:22] [API] Get thumbnail for document 23
[6/5/2024, 18:22] [API] Get thumbnail for document 24
[6/5/2024, 18:22] [API] Get thumbnail for document 25
[6/5/2024, 18:22] [API] StoragePath API sequence fetch was empty
[6/5/2024, 18:22] [API] Correspondent API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] DocumentType API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] Tag API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] User API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [General] App becomes inactive
[6/5/2024, 18:22] [Migration] Skipping migration
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [General] App becomes active
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [API] Getting document sequence for filter
[6/5/2024, 18:22] [API] Document API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] Get thumbnail for document 25
[6/5/2024, 18:22] [API] Get thumbnail for document 24
[6/5/2024, 18:22] [API] Get thumbnail for document 23
[6/5/2024, 18:22] [API] Get thumbnail for document 22
[6/5/2024, 18:22] [API] Get thumbnail for document 21
[6/5/2024, 18:22] [API] Get thumbnail for document 20
[6/5/2024, 18:22] [API] Get thumbnail for document 19
[6/5/2024, 18:22] [API] Get thumbnail for document 18
[6/5/2024, 18:22] [API] Get thumbnail for document 17
[6/5/2024, 18:22] [API] Get thumbnail for document 16
[6/5/2024, 18:22] [API] Get thumbnail for document 15
[6/5/2024, 18:22] [API] Get thumbnail for document 14
[6/5/2024, 18:22] [API] Get thumbnail for document 13
[6/5/2024, 18:22] [API] Get thumbnail for document 12
[6/5/2024, 18:22] [API] Get thumbnail for document 11
[6/5/2024, 18:22] [API] Get thumbnail for document 10
[6/5/2024, 18:22] [API] Get thumbnail for document 9
[6/5/2024, 18:22] [API] Get thumbnail for document 8
[6/5/2024, 18:22] [API] Get thumbnail for document 2
[6/5/2024, 18:22] [API] Get thumbnail for document 1
[6/5/2024, 18:22] [API] Get thumbnail for document 22
[6/5/2024, 18:22] [API] Get thumbnail for document 22
[6/5/2024, 18:22] [API] Get thumbnail for document 23
[6/5/2024, 18:22] [API] Get thumbnail for document 24
[6/5/2024, 18:22] [API] Get thumbnail for document 25
[6/5/2024, 18:22] [General] Fetch all store request
[6/5/2024, 18:22] [General] Fetch all store
[6/5/2024, 18:22] [API] StoragePath API sequence fetch was empty
[6/5/2024, 18:22] [API] Unable to decode response to https://example.com/api/saved_views/?page_size=100000 as ListResponse<SavedView> from body {"count":1,"next":null,"previous":null,"all":[1],"results":[{"id":1,"name":"inbox","show_on_dashboard":true,"show_in_sidebar":true,"sort_field":"score","sort_reverse":false,"filter_rules":[{"rule_type":20,"value":"inbox"}],"page_size":null,"display_mode":null,"display_fields":null,"owner":3,"user_can_change":true}]}: Error Domain=NSCocoaErrorDomain Code=4864 UserInfo={NSCodingPath=<private>, NSDebugDescription=<private>}
[6/5/2024, 18:22] [API] Correspondent API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] DocumentType API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] Tag API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] User API sequence has reached end (nextPage is nil)
[6/5/2024, 18:22] [API] Error in SavedView API sequence: dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "results", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "sort_field", intValue: nil)], debugDescription: "Cannot initialize SortField from invalid String value score", underlyingError: nil))
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [API] Getting connection from stored connection: https://user-ff5884e4@debc8b83.example.com
[6/5/2024, 18:22] [General] Requesting log export
paulgessinger commented 1 month ago

Hey @timespaced, That looks different indeed. What are you sorting on in that saved view?

paulgessinger commented 1 month ago

@timespaced Build 85 on TestFlight should at least be able to decode your saved view now.

The UI will not play nice with this yet. I don't know how to create a saved view like that in the web view, and I don't have a good way to mock API responses for UI tests yet.

paulgessinger commented 1 month ago

@timespaced could you help reproduce this on my end so I can test the UI for this?

paulgessinger commented 1 month ago

Ok I got it with some help from @shamoon. It's the search score for advanced searches! I'll put a proper fix in tomorrow.

timespaced commented 1 month ago

@paulgessinger Hi Paul, sorry for the delay. The only Saved View I have is a "tag" search for the "inbox" tag.

Happy to help in any way I can - let me know.

paulgessinger commented 1 month ago

Hey @timespaced, I pushed build 86 to TestFlight which should now properly decode this, and have UI to work with it. On that note, I believe you're actually sorting by the search score in your inbox view, which means the order is probably arbitrary.

Anyway, let me know if you had a chance to check it out, so I can close this!