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

Terminating app due to uncaught exception 'RLMExecption', reason: ''RealmSwiftObject' does not have a primary key and can not be updated' #6159

Closed
ppamorim opened this issue May 31, 2019 · 2 comments · Fixed by #6160
Assignees

Comments

@ppamorim
Copy link

ppamorim commented May 31, 2019

Actual Results

Steps to Reproduce

Yes my object has a primary key and the first write is successful.

Use realm.create(type(of: object), value: object, update: .all) to write a managed object into another Realm instance of another file. Also all my unit tests are failing.
I had to downgrade to v3.15.0 to stop the problem. All the problems are gone.
I will try to replicate this on a sample, meanwhile you guy can try to analyse it based on my logs.

Code Sample

let object: RealmSwift.Object = //....

var config: Realm.Configuration = anotherSchema()
config.fileURL = config.fileURL?.deletingLastPathComponent().appendingPathComponent("another.realm")

let realm: Realm = try Realm(configuration: config)
try realm.write {
  realm.create(type(of: object), value: object, update: .all) //<-- Crash, also crash with 'true'.
}

Version of Realm and Tooling

Realm framework version: v3.16.0

Realm Object Server version: No

Xcode version: 10.2.1

iOS/OSX version: Any

Dependency manager + version: Submodules

Log:

Realm is calling my Object as RealmSwiftObject by some reason...

/Users/ppamorim/Repository/app/UnitTests/Repository/SomeTest.swift:49: error: -[UnitTests.SomeTest testLoadSomething] : failed: caught "RLMExecption", "'RealmSwiftObject' does not have a primary key and can not be updated"
(
	0   CoreFoundation                      0x000000018377717c <redacted> + 148
	1   libobjc.A.dylib                     0x00000001829c0528 objc_exception_throw + 56
	2   Realm                               0x000000010447ddc8 RLMVerifyHasPrimaryKey + 236
	3   RealmSwift                          0x000000010411086c $s10RealmSwift0A0C6create_5value6updatexxm_ypAC12UpdatePolicyOtAA6ObjectCRbzlF + 56
	4   App                       0x0000000101502ec4 $s13App6backupyy10RealmSwift6ObjectCSgFyyXEfU_yyXEfU0_ + 192
	5   RealmSwift                          0x000000010410fc30 $s10RealmSwift0A0C5writeyyyyKXEKF + 60
	6   App                       0x0000000101502988 $s13App6backupyy10RealmSwift6ObjectCSgFyyXEfU_ + 1748
	7   App                       0x00000001011115fc $ss5Error_pIgzo_ytsAA_pIegrzo_TR + 32
	8   App                       0x0000000101502d90 $ss5Error_pIgzo_ytsAA_pIegrzo_TRTA.26 + 40
	9   libswiftObjectiveC.dylib            0x0000000107786cec $s10ObjectiveC15autoreleasepool8invokingxxyKXE_tKlF + 56
	10  App                       0x000000010150223c $s13App6backupyy10RealmSwift6ObjectCSgF + 264
	11  App                       0x0000000101128b24 $s13App30addOrUpdateDataOnDatabase5realm09unmanagedfG0AA0fG0CSg10RealmSwift0L0C_AFtFyyKXEfU_yyXEfU_ + 1220
	12  RealmSwift                          0x000000010410fc30 $s10RealmSwift0A0C5writeyyyyKXEKF + 60
	13  App                       0x000000010112850c $s13App30addOrUpdateDataOnDatabase5realm09unmanagedfG0AA0fG0CSg10RealmSwift0L0C_AFtFyyKXEfU_ + 200
	14  App                       0x00000001011285f8 $s13App30addOrUpdateDataOnDatabase5realm09unmanagedfG0AA0fG0CSg10RealmSwift0L0C_AFtFyyKXEfU_TA + 44
	15  App                       0x00000001011115fc $ss5Error_pIgzo_ytsAA_pIegrzo_TR + 32
	16  App                       0x0000000101128650 $ss5Error_pIgzo_ytsAA_pIegrzo_TRTA.33 + 40
	17  libswiftObjectiveC.dylib            0x0000000107786cec $s10ObjectiveC15autoreleasepool8invokingxxyKXE_tKlF + 56
	18  App                       0x0000000101128244 $s13App30addOrUpdateDataOnDatabase5realm09unmanagedfG0AA0fG0CSg10RealmSwift0L0C_AFtF + 256
	19  UnitTests                           0x000000010914c940 $s9UnitTests23SomeTestC08testLoadcD0yyF + 572
	20  UnitTests                           0x000000010914e1d0 $s9UnitTests23SomeTestC08testLoadcD0yyFTo + 40
	21  CoreFoundation                      0x000000018377ead0 <redacted> + 144
	22  CoreFoundation                      0x000000018365d36c <redacted> + 292
	23  XCTest                              0x00000001078ca00c __24-[XCTestCase invokeTest]_block_invoke_2.200 + 68
	24  XCTest                              0x0000000107931ef8 -[XCTMemoryChecker _assertInvalidObjectsDeallocatedAfterScope:] + 68
	25  XCTest                              0x00000001078d2604 -[XCTestCase assertInvalidObjectsDeallocatedAfterScope:] + 112
	26  XCTest                              0x00000001078c9f98 __24-[XCTestCase invokeTest]_block_invoke.194 + 196
	27  XCTest                              0x000000010791eed4 -[XCTestCase(Failures) performFailableBlock:testCaseRun:shouldInterruptTest:] + 64
	28  XCTest                              0x000000010791edec -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 108
	29  XCTest                              0x00000001078c9bc8 __24-[XCTestCase invokeTest]_block_invoke + 808
	30  XCTest                              0x0000000107924e8c -[XCUITestContext performInScope:] + 144
	31  XCTest                              0x00000001078c97cc -[XCTestCase testContextPerformInScope:] + 120
	32  XCTest                              0x00000001078c988c -[XCTestCase invokeTest] + 140
	33  XCTest                              0x00000001078cb35c __26-[XCTestCase performTest:]_block_invoke_2 + 44
	34  XCTest                              0x000000010791eed4 -[XCTestCase(Failures) performFailableBlock:testCaseRun:shouldInterruptTest:] + 64
	35  XCTest                              0x000000010791edec -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 108
	36  XCTest                              0x00000001078cb274 __26-[XCTestCase performTest:]_block_invoke.324 + 96
	37  XCTest                              0x000000010792f440 +[XCTContext runInContextForTestCase:block:] + 216
	38  XCTest                              0x00000001078caa2c -[XCTestCase performTest:] + 644
	39  XCTest                              0x000000010790c0e8 -[XCTest runTest] + 60
	40  XCTest                              0x00000001078c581c __27-[XCTestSuite performTest:]_block_invoke + 280
	41  XCTest                              0x00000001078c513c -[XCTestSuite _performProtectedSectionForTest:testSection:] + 68
	42  XCTest                              0x00000001078c53d8 -[XCTestSuite performTest:] + 276
	43  XCTest                              0x000000010790c0e8 -[XCTest runTest] + 60
	44  XCTest                              0x00000001078c581c __27-[XCTestSuite performTest:]_block_invoke + 280
	45  XCTest                              0x00000001078c513c -[XCTestSuite _performProtectedSectionForTest:testSection:] + 68
	46  XCTest                              0x00000001078c53d8 -[XCTestSuite performTest:] + 276
	47  XCTest                              0x000000010790c0e8 -[XCTest runTest] + 60
	48  XCTest                              0x00000001078c581c __27-[XCTestSuite performTest:]_block_invoke + 280
	49  XCTest                              0x00000001078c513c -[XCTestSuite _performProtectedSectionForTest:testSection:] + 68
	50  XCTest                              0x00000001078c53d8 -[XCTestSuite performTest:] + 276
	51  XCTest                              0x000000010790c0e8 -[XCTest runTest] + 60
	52  XCTest                              0x000000010793c6a8 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke + 176
	53  XCTest                              0x000000010793c778 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke.80 + 60
	54  XCTest                              0x00000001078dc6d0 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 516
	55  XCTest                              0x000000010793c464 -[XCTTestRunSession runTestsAndReturnError:] + 596
	56  XCTest                              0x00000001078aa704 -[XCTestDriver runTestsAndReturnError:] + 436
	57  XCTest                              0x000000010792b8c0 _XCTestMain + 2248
	58  libXCTestBundleInject.dylib         0x000000010285579c __copy_helper_block_e8_32s + 0
	59  CoreFoundation                      0x000000018371f590 <redacted> + 20
	60  CoreFoundation                      0x000000018371ee60 <redacted> + 288
	61  CoreFoundation                      0x000000018371cb70 <redacted> + 1068
	62  CoreFoundation                      0x000000018363cc58 CFRunLoopRunSpecific + 436
	63  GraphicsServices                    0x00000001854e8f84 GSEventRunModal + 100
	64  UIKit                               0x000000018cd955c4 UIApplicationMain + 236
	65  App                       0x00000001014a7ac8 main + 76
	66  libdyld.dylib                       0x000000018315c56c <redacted> + 4
)
@RMizin
Copy link

RMizin commented May 31, 2019

+1
Exactly the same problem on 3.16.0, but works perfectly on 3.15.0.

 static func create<T: Object>(objects: [T], update: Bool = true) {
		try! RealmManager.defaultRealm.safeWrite {
			for object in objects {
				RealmManager.defaultRealm.create(T.self, value: object, update: update) // crash with (true, .all, .modified)
			}
		}
	}

@tgoyne
Copy link
Member

tgoyne commented May 31, 2019

I think I see what may have changed here. Things like realm.create<BaseClass>(type: Subclass.self, value: ...) where the statically determined type and the type object passed in at runtime used to work by coincidence, but since it wasn't intended functionality there weren't any tests verifying that and I changed a check to use the static type where it previously used the dynamic type. Should be easy to fix and make it officially supported.

@tgoyne tgoyne added the T-Bug label May 31, 2019
@tgoyne tgoyne self-assigned this May 31, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants