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

fix: save code references before key metas to workaround hibernate bug #2837

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ class SingleStepImportControllerTest : ProjectAuthControllerTest("/v2/projects/"
@Value("classpath:import/xliff/simple.xliff")
lateinit var simpleXliff: Resource

@Value("classpath:import/po/codeReferences.po")
lateinit var codeReferencesPo: Resource

lateinit var testData: SingleStepImportTestData

private val xliffFileName: String = "file.xliff"
private val poFileName = "file.po"
private val jsonFileName = "en.json"

@BeforeEach
Expand All @@ -60,6 +64,20 @@ class SingleStepImportControllerTest : ProjectAuthControllerTest("/v2/projects/"
}
}

@Test
@ProjectJWTAuthTestMethod
fun `import po with code references`() {
saveAndPrepare()
performImport(
projectId = testData.project.id,
listOf(Pair(poFileName, codeReferencesPo)),
)
executeInNewTransaction {
assertPoImported()
getTestTranslation().key.keyMeta!!.codeReferences.map { it.path }.assert.contains("dir/file.py")
}
}

@Test
@ProjectJWTAuthTestMethod
fun `does not create new key if option isn't enabled`() {
Expand Down Expand Up @@ -394,6 +412,10 @@ class SingleStepImportControllerTest : ProjectAuthControllerTest("/v2/projects/"
getTestTranslation().text.assert.isEqualTo("test")
}

private fun assertPoImported() {
getTestTranslation().text.assert.isEqualTo("In English!")
}

private fun saveAndPrepare() {
testDataService.saveTestData(testData.root)
userAccount = testData.user
Expand Down
12 changes: 12 additions & 0 deletions backend/app/src/test/resources/import/po/codeReferences.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
msgid ""
msgstr ""
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals = 2; plural = (n > 1)\n"
"X-Generator: Tolgee\n"

#: dir/file.py:42
msgid "test"
msgstr "In English!"
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ class StoredDataImporter(
}

private fun saveKeyMetaData(keyEntitiesToSave: Collection<Key>) {
keyMetaService.saveAll(keyMetasToSave)
keyEntitiesToSave.flatMap {
it.keyMeta?.comments ?: emptyList()
}.also { keyMetaService.saveAllComments(it) }
keyEntitiesToSave.flatMap {
it.keyMeta?.codeReferences ?: emptyList()
}.also { keyMetaService.saveAllCodeReferences(it) }
keyMetaService.saveAll(keyMetasToSave)
}

private fun saveTranslations() {
Expand Down
Loading