Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in Filtered View? #256

Closed
dispatchqueue opened this issue Dec 29, 2015 · 1 comment
Closed

Bug in Filtered View? #256

dispatchqueue opened this issue Dec 29, 2015 · 1 comment

Comments

@dispatchqueue
Copy link
Contributor

I replace metadata by using replaceMetadata method.
In the method handleReplaceMetadata of YapDatabaseFilteredViewTransaction, I found this code (https://github.com/yapstudios/YapDatabase/blob/master/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.m#L1005-L1018):

    id object = nil;
    if ((sortingMayHaveChanged && sortingNeedsObject) || (filteringMayHaveChanged && filteringNeedsObject))
    {
        object = [databaseTransaction objectForCollectionKey:collectionKey withRowid:rowid];
    }

    [self _handleChangeWithRowid:rowid
                   collectionKey:collectionKey
                          object:object
                        metadata:metadata
                       filtering:filtering
              blockInvokeBitMask:blockInvokeBitMask
                  changesBitMask:changesBitMask
                        isInsert:NO];

sortingMayHaveChanged and filteringMayHaveChanged are NO because the parent view is sorted and filtered by object, so object variable is nil. This object variable is passed to _handleChangeWithRowid.

In the method _handleChangeWithRowid, filteringMayHaveChanged is NO because parent view is filtered by object, and passesFilter is set to YES in the line 834. The filtered view extension will then insert row:

    if (passesFilter)
    {
        // Add row to view (or update position).

        [self insertRowid:rowid
            collectionKey:collectionKey
                   object:object
                 metadata:metadata
                  inGroup:group
              withChanges:changesBitMask
                    isNew:NO];

        lastHandledGroup = group;
    }

At this point, object is nil because it is not get in the code above. And in method insertRowid, the sortingBlock is called with the first object is nil (https://github.com/yapstudios/YapDatabase/blob/master/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.m#L1883-L1896).
object1 and object2 should not be nil in a sorting block, right?

Thanks.

robbiehanson added a commit that referenced this issue Dec 30, 2015
@robbiehanson
Copy link
Contributor

Great catch. Should be fixed in the master branch (and the "v2.8" branch too). Let me know if you have any other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants