GRDB.swift: Crash when observing virtual table?

What did you do?

I have two tables, one that contains just the contents of a specific record type and another that is a FTS4 search index table of said the previously mentioned content.

Both tables have a corresponding type (struct conforming to TableRecord and FetchableRecord). The type that represents a row in the “regular” table defines a hasOne association with the search index type.

When performing a search in the app I create a QueryInterfaceRequest that among other things joins on the hasOne association which allows me to filter the request on matches in the index table.

It looks like this:

RecipePreview
            .joining(required: RecipePreview.index)
            .order(RecipePreview.Columns.name)
            .filter(filter.filter)
            .filter(tags: tags)
            .filter(query: query)

The query filter is just this extension on QueryInterfaceRequest:

    func filter(query: String?) -> QueryInterfaceRequest {
        guard let query = query?.trimmingCharacters(in: .whitespacesAndNewlines), !query.isEmpty else {
            return self
        }
        return self.filter(sql: "recipeSearchIndex.corpus MATCH ?", arguments: ["*\(query)*"])
    }

What did you expect to happen?

In most cases this works great and allows me to use a UISearchController to populate a collection view with the search results. However, I also observe this request because these items can be “favorited”, among other things, which changes the display of the item in the list.

What happened instead?

Whenever a search is performed while the search index is update I get a fatalError on line 201 of DatabaseRegion.swift stating:

precondition failure: event was not filtered out in observes(eventsOfKind:) by region.isModified(byEventsOfKind:)

Environment

GRDB flavor(s): GRDB GRDB version: 4.2.1 Installation method: Manual (git submodule) Xcode version: 11 Swift version: 5.1 Platform(s) running GRDB: iOS macOS version running Xcode: 10.15 beta… 8?


I realise this probably has something to do with the virtual table. I guess my main questions is: is this a bug or intended behaviour? And can it be worked around somehow?

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Fixed! I’m closing this issue in favor of #622.

Don’t mean to impose stress because of my spamming. Just posting my findings while debugging in hopes of rubber ducking to make myself understand what’s going on and helping you help me 😄

@simme, I’ll have a look shortly.