Core Data fetch returns duplicate managed objects

Originator:hamish
Number:rdar://12965555 Date Originated:07-Jan-2013 03:35 PM
Status:Open Resolved:
Product:iPhone SDK Product Version:6.0.1
Classification:Serious Bug Reproducible:Always
 
Summary:

A Core Data fetch should return one and only one of each managed object corresponding to the requested entity. However, under certain circumstances, it returns multiple copies of the same managed object:

2013-01-07 14:46:17.561 CoreDataOuterJoinBugTest[3913:c07] CoreData: annotation: fetch using NSSQLiteStatement <0x81d3400> on entity 'Entity1' with sql text 'SELECT 0, t0.Z_PK, t0.Z_OPT FROM ZENTITY1 t0 LEFT OUTER JOIN Z_1E2A t1 ON t0.Z_PK = t1.Z_1E1A LEFT OUTER JOIN Z_1E2B t3 ON t0.Z_PK = t3.Z_1E1B WHERE (t1.Z_2E2A = ? OR t3.Z_2E2B = ?) ' returned 6 rows with values: (
    "<NSManagedObject: 0x748bd50> (entity: Entity1; id: 0x7486f80 <x-coredata://5BB01AA0-BC59-4E1B-A501-C22E55534A73/Entity1/p1> ; data: <fault>)",
    "<NSManagedObject: 0x748bd50> (entity: Entity1; id: 0x7486f80 <x-coredata://5BB01AA0-BC59-4E1B-A501-C22E55534A73/Entity1/p1> ; data: <fault>)",
    "<NSManagedObject: 0x748bd50> (entity: Entity1; id: 0x7486f80 <x-coredata://5BB01AA0-BC59-4E1B-A501-C22E55534A73/Entity1/p1> ; data: <fault>)",
    "<NSManagedObject: 0x748c010> (entity: Entity1; id: 0x7472790 <x-coredata://5BB01AA0-BC59-4E1B-A501-C22E55534A73/Entity1/p2> ; data: <fault>)",
    "<NSManagedObject: 0x748c010> (entity: Entity1; id: 0x7472790 <x-coredata://5BB01AA0-BC59-4E1B-A501-C22E55534A73/Entity1/p2> ; data: <fault>)",
    "<NSManagedObject: 0x748c010> (entity: Entity1; id: 0x7472790 <x-coredata://5BB01AA0-BC59-4E1B-A501-C22E55534A73/Entity1/p2> ; data: <fault>)"

Steps to Reproduce:

The enclosed project contains the minimum code to reproduce.

Expected Results:

The SQL text above should read "SELECT DISTINCT..." when the query has been re-written to use an outer join (because primary keys are no longer unique in the joined table). This query would return the correct result of 2 rows.

Actual Results:

The SQL text above reads "SELECT..." and the query returns 6 rows.

Regression:

Unknown.

Notes:

Thank you!

Comments

The enclosed project

For "the enclosed project", please visit https://github.com/hatfinch/sample-projects/tree/master/CoreDataOuterJoinBugTest


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!