MerginMaps / mobile

Mobile app for Mergin Maps 📲. Open QGIS projects and manage vector data on your phone, even offline 📶 (Android/iOS/Windows app)
https://merginmaps.com
GNU General Public License v2.0
294 stars 64 forks source link

Fix not null value relation #3446

Closed uclaros closed 4 months ago

uclaros commented 4 months ago

This is an attempt to Fix #3418

The bug is as follows: Not null constraint on multi-select value relations is not met when selecting values, but works OK as long as a single value is deselected.

If there is no not null constraint, the log looks like this when clicking confirm selection :

"Search (0) completed after 7ms, results: 1191"
"Search (0) completed after 3ms, results: 10"
"Search (0) completed after 4ms, results: 1191"
DEBUG  QList(273)   QVariant(QString, "{BS04.01}")
DEBUG  QList(260, 261)   QVariant(QString, "{BS04.01}")
"Search (1) completed after 0ms, results: 10"
"Search (1) completed after 3ms, results: 1191"

When the not null constraint is set, there appears a binding loop :

"Search (2) completed after 6ms, results: 10"
"Search (5) completed after 13ms, results: 1191"
"Search (0) completed after 0ms, results: 10"
"Search (0) completed after 3ms, results: 1191"
DEBUG  QList(273)   QVariant(QString, "{BS04.01}")
DEBUG  QList(260, 261)   QVariant(QString, "{BS04.01}")
DEBUG  QList()   QVariant(QString, "{BS04.01}")
DEBUG  QList(273)   QVariant(Invalid)
qrc:/com.merginmaps/imports/MMInput/form/MMFormPage.qml:267:7: QML Loader: Binding loop detected for property "fieldValue"
DEBUG  QList(260, 261)   QVariant(Invalid)
DEBUG  QList()   QVariant(Invalid)
qrc:/com.merginmaps/imports/MMInput/form/MMFormPage.qml:267:7: QML Loader: Binding loop detected for property "fieldValue"
"Search (6) was canceled after 0ms, results: 120"
"Search (1) completed after 0ms, results: 10"
"Search (7) completed after 3ms, results: 1191"

And if a second value is checked and then immediately unchecked, it works correctly and the log is:

"Search (0) completed after 14ms, results: 1191"
"Search (0) completed after 3ms, results: 10"
"Search (0) completed after 3ms, results: 1191"
DEBUG  QList(273)   QVariant(QString, "{BS04.01}")
DEBUG  QList(260, 261)   QVariant(QString, "{BS04.01}")
DEBUG  QList()   QVariant(QString, "{BS04.01}")
"Search (1) completed after 0ms, results: 10"
"Search (1) completed after 3ms, results: 1191"

When unchecking a value, the array containing the selected ids is copied

root.selected = root.selected.filter( ( x ) => x !== val )

which apparently fixes the issue... So creating a copy of the array when adding values too brings us the expected behavior!

This is fixing the symptom instead of the cause, so @tomasMizera I think I need your wisdom!

tomasMizera commented 4 months ago

Does it fix the issue now @uclaros? :)

tomasMizera commented 4 months ago

If you merge master here, the iOS CI will pass

uclaros commented 4 months ago

Does it fix the issue now @uclaros? :)

Yes, this fixes it!

tomasMizera commented 4 months ago

Test CI failures seem unrelated