diff --git a/collect_app/src/main/java/org/odk/collect/android/database/entities/DatabaseEntitiesRepository.kt b/collect_app/src/main/java/org/odk/collect/android/database/entities/DatabaseEntitiesRepository.kt index 57dc54a8de3..b3e127ca42c 100644 --- a/collect_app/src/main/java/org/odk/collect/android/database/entities/DatabaseEntitiesRepository.kt +++ b/collect_app/src/main/java/org/odk/collect/android/database/entities/DatabaseEntitiesRepository.kt @@ -383,6 +383,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep val missingColumns = entity.properties .map { EntitiesTable.getPropertyColumn(it.first) } .filterNot { columnNames.contains(it) } + .distinctBy { it.lowercase() } if (missingColumns.isNotEmpty()) { databaseConnection.resetTransaction { diff --git a/collect_app/src/test/java/org/odk/collect/android/entities/EntitiesRepositoryTest.kt b/collect_app/src/test/java/org/odk/collect/android/entities/EntitiesRepositoryTest.kt index 6b9d3d27c72..018721f55e3 100644 --- a/collect_app/src/test/java/org/odk/collect/android/entities/EntitiesRepositoryTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/entities/EntitiesRepositoryTest.kt @@ -644,4 +644,19 @@ abstract class EntitiesRepositoryTest { repository.updateListHash("wine", "2024") assertThat(repository.getListHash("wine"), equalTo("2024")) } + + @Test + fun `#save ignores case-insensitive duplicate properties`() { + val repository = buildSubject() + val entity = Entity.New( + "1", + "One", + properties = listOf(Pair("prop", "value"), Pair("Prop", "value")) + ) + + repository.save("things", entity) + val savedEntities = repository.getEntities("things") + assertThat(savedEntities[0].properties.size, equalTo(1)) + assertThat(savedEntities[0].properties[0].first, equalTo("prop")) + } } diff --git a/entities/src/main/java/org/odk/collect/entities/storage/InMemEntitiesRepository.kt b/entities/src/main/java/org/odk/collect/entities/storage/InMemEntitiesRepository.kt index 4ea4afd4f29..e467df1a104 100644 --- a/entities/src/main/java/org/odk/collect/entities/storage/InMemEntitiesRepository.kt +++ b/entities/src/main/java/org/odk/collect/entities/storage/InMemEntitiesRepository.kt @@ -123,7 +123,12 @@ class InMemEntitiesRepository : EntitiesRepository { lists.add(list) listProperties.getOrPut(list) { mutableSetOf() - }.addAll(entity.properties.map { it.first }) + }.addAll( + entity + .properties + .distinctBy { it.first.lowercase() } + .map { it.first } + ) } private fun mergeProperties(