Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Using Tap Forms › Records unexpectedly disappearing when unlinking record from linked from field
- This topic has 12 replies, 3 voices, and was last updated 3 years, 5 months ago by Brendan.
-
AuthorPosts
-
April 8, 2021 at 12:39 PM #44085
cfParticipantI’ve been noticing that records have been disappearing seemingly randomly and finally figured out what’s going on. When unlinking a record on the “Linked From” side of a relation, it unlinks ALL records on the “Linked To” side of the relationship. A common case where this will occur is if you are using linked forms to model tagging. If your parent form uses a “Linked To” relation to a tag form, and you unlink a tag from the tag form side, the record in the parent form will lose all its tags.
More details instructions to reproduce, I’ve attached an example archive to help illustrate the issue:
1. Say you have two forms, “Food” and “Food Tags”. “Food” contains a “Linked To” field to “Food Tags”, with “Show Inverse Relationship” enabled so that “Food” appears as a “Linked From” field in “Food Tags”. This is a pretty common setup to allow tagging content.
2. There are three tags in the “Food Tags” form: “Tag1”, “Tag2”, “Tag3” and three items in the “Food” form: “Apple”, “Broccoli”, “Orange”.
3. Each of the records in “Food” has all three tags linked. So when viewing the “Apple” record you will see it has “Tag1”, “Tag2”, “Tag3” listed in the “Linked To” field, same with the other two records.
4. Likewise, when viewing any record on “Food Tags”, each tag will show all three linked “Food” records in its “Linked From” field.
5. Now from the “Food Tags” form, select “Tag1”, then select “Apple” from the “Linked From”.
6. Click the minus sign and choose “Unlink” when the dialog pops up.
7. “Apple” is now no longer linked to “Tag1”, as expected. However, selecting “Tag2” and “Tag3” reveals that “Apple” is no longer linked to any of the tags. This can also be seen by selecting “Apple” from the “Food” form and noticing that the “Linked To” field is now empty. Despite only unlinking “Tag1”, all tags are now gone.This happens any time you unlink a record from the “Linked From” side of a relationship. If you had done the same steps of unlinking “Tag1” from the “Food” form then only “Apple” <-> “Tag1” would be unlinked.
It doesn’t matter which way you define the relationship. If you have made the “Food Tags” form the parent with the “Linked To” to “Food” and unlinked on the “Food” side you will get the same behavior.
Attachments:
You must be logged in to view attached files.April 9, 2021 at 1:58 AM #44091
BrendanKeymasterHi Christian,
Thanks for the sample file and the bug report.
I’ve confirmed that it appears this is happening from the inverse relationship side.
I’ll work on a fix for it.
Thanks,
Brendan
April 9, 2021 at 6:50 AM #44093
cfParticipantWhile you are poking around in that code, I also ran into a crash when adding a linked record using the plus-arrow button (the one that adds a record and navigates to it). Unfortunately I am unable to create steps to reproduce since it only happens for some records/forms and not others. In the cases where the crash does occur it happens consistently.
Linked below is the stack trace:
https://gist.github.com/cfilipov/0a6559c7b010ac651c2dfe27cc67a6b2
The relevant part:
Application Specific Information: Crashing on exception: *** -[__NSArrayM objectAtIndexedSubscript:]: index 3 beyond bounds [0 .. 2] Application Specific Backtrace 1: 0 CoreFoundation 0x00007fff204cc6af __exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007fff202043c9 objc_exception_throw + 48 2 CoreFoundation 0x00007fff20580a9a -[__NSCFString characterAtIndex:].cold.1 + 0 3 CoreFoundation 0x00007fff2043fe41 -[__NSArrayM objectAtIndexedSubscript:] + 169 4 Tap Forms Mac 5 0x000000010711c14e Tap Forms Mac 5 + 1675598 5 AppKit 0x00007fff22e87412 -[_NSCollectionViewDataSourceAdapter collectionView:itemForRepresentedObjectAtIndexPath:] + 435 6 UIFoundation 0x00007fff239e4823 -[_NSCollectionViewCore _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 100 7 UIFoundation 0x00007fff239e47b9 -[_NSCollectionViewCore _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 31 8 UIFoundation 0x00007fff239cc726 -[_NSCollectionViewCore _updateVisibleCellsNow:] + 4435 9 UIFoundation 0x00007fff239cdb5a -[_NSCollectionViewCore _updateVisibleCellsNow:] + 9607 10 UIFoundation 0x00007fff239c0a41 -[_NSCollectionViewCore _layoutItems] + 285 11 UIFoundation 0x00007fff23aa0829 -[_NSCollectionViewCore _itemAtIndexPath:includePrefetchedCells:] + 230 12 UIFoundation 0x00007fff23a9a5ac __76-[_NSCollectionViewCore _deselectItemsAtIndexPaths:animated:notifyDelegate:]_block_invoke + 37 13 CoreFoundation 0x00007fff2048199c __NSSET_IS_CALLING_OUT_TO_A_BLOCK__ + 7 14 CoreFoundation 0x00007fff204c40fc -[__NSSingleObjectSetI enumerateObjectsWithOptions:usingBlock:] + 111 15 UIFoundation 0x00007fff23a9a525 -[_NSCollectionViewCore _deselectItemsAtIndexPaths:animated:notifyDelegate:] + 382 16 AppKit 0x00007fff235f9433 -[NSCollectionView _deselectItemsAtIndexPaths:notifyDelegate:] + 144 17 Tap Forms Mac 5 0x000000010705d805 Tap Forms Mac 5 + 894981 18 Tap Forms Mac 5 0x000000010705bf21 Tap Forms Mac 5 + 888609
I had three linked records and used the arrow-plus button to add a fourth.
April 9, 2021 at 7:17 PM #44098
BrendanKeymasterDoes it happen in the sample form you sent me?
Sorry, I should check myself, but I haven’t had time to dig into it just yet today.
April 12, 2021 at 8:54 AM #44129
cfParticipantUnfortunately I have been unable to find a way to make this into a minimal reproducible example. I was hoping the stack trace would give you some info.
April 12, 2021 at 7:37 PM #44137
BrendanKeymasterIt looks like something to do with the Photo Grid view. Thats’ one of the only places I use the NSCollectionView. But the error tells me that the code was accessing an item from an array that didn’t exist. Index out of bounds. Pinpointing it would be difficult without the database to work with and the steps used to reproduce the bug.
April 13, 2021 at 9:35 AM #44145
cfParticipantI’m trying to figure out the steps to reproduce. Even on the form where it was happening it was not consistent. Right now I am able to add items without crashing. Once I get it to crash once it will happen consistently from then on until some time later. I figured I might as well share whatever details I do have in case you see something more. In any case I feel like a crash is less severe than the original issue in this thread. Thank you.
April 13, 2021 at 7:45 PM #44147
Sam MoffattParticipantDo you have fields scripts that work on the record? There might be a data race with the layout renderer and something mutating the record state?
April 15, 2021 at 12:54 PM #44170
cfParticipantHi Sam, I do have field scripts and when I get into a state where I am able to reproduce I did try to comment out all the code in the scripts to rule that out, crash still occurred. I agree this has the markings of a race condition though unlike a typical race condition once im able to get into a state where it’s reproducible its consistently reproducible with those records.
Anyway I don’t want this crash to distract from the original issue I posted, which I think is much more serious and very eager to see a fix for.
April 16, 2021 at 12:25 AM #44175
BrendanKeymasterI managed to get this one fixed (the unlinking issue with inverse many-to-many relationships). It was tricky and took some deep diving into the code, but I got it. Yay!
April 16, 2021 at 6:34 AM #44178
cfParticipantThat’s great news, thank you!
May 26, 2021 at 6:58 AM #44460
cfParticipantAny indication when this fix will be released? This is (imo) a fairly serious issue which appears to have effected at least one other user posting in here.
May 27, 2021 at 2:28 AM #44470
BrendanKeymasterHi Cristian,
Did I not give you access to the beta with this fix?
I should. Sorry. I’ve been working on learning some SwiftUI code recently, so haven’t released the update. I should get on that. Sorry for the delay.
Brendan
-
AuthorPosts
You must be logged in to reply to this topic.