Skip to content

Fix duplicate currency name check when using --rename flag#195

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-currency-creation-error
Draft

Fix duplicate currency name check when using --rename flag#195
Copilot wants to merge 2 commits intomainfrom
copilot/fix-currency-creation-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 13, 2025

Currency creation fails with SQL constraint violation (error 23505) when using --rename or --no-rename flags because the duplicate name check includes flags while the actual currency name filters them out.

Changes

  • CurrencyCreateCommand.kt: Changed duplicate check from args.joinToString(" ") to use currencyName variable

The currency name is constructed by filtering command flags:

val currencyName = args.filter { it !in listOf("--rename", "--no-rename") }.joinToString(" ")

But the duplicate check was using raw arguments with flags included:

// Before: checks for "SantiagoReal --rename" (not found)
val existingCurrency = currencyService.getCurrency(args.joinToString(" "))

// After: checks for "SantiagoReal" (found if exists)
val existingCurrency = currencyService.getCurrency(currencyName)

This mismatch allowed duplicate currencies to bypass validation and hit the database unique constraint on currencies_currency.name.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • hub.spigotmc.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=256m (dns block)
  • jitpack.io
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=256m (dns block)
  • repo.dansplugins.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=256m (dns block)
  • repo.extendedclip.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=256m (dns block)
  • repo.mikeprimm.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=256m (dns block)
  • repo.rpkit.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=256m (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Error when creating a Currency</issue_title>
<issue_description>
Newest MedievalFactions & Currencies Version
Paper 1.21.3 newest Build

[21:09:27 INFO]: gmrrh issued server command: /currency create SantiagoReal
[21:09:29 INFO]: gmrrh issued server command: /currency create SantiagoReal --rename
[21:09:29 ERROR]: [Currencies] Failed to save currency: Service error: SQL [merge into "currencies_currency" using (select "t"."id", "t"."version", "t"."faction_id", "t"."name", "t"."description", "t"."item", "t"."amount", "t"."status", "t"."legacy_id" from (select cast(? as varchar(36)), cast(? as int), cast(? as varchar(36)), cast(? as varchar(256)), cast(? as varchar(4096)), cast(? as blob), cast(? as int), cast(? as varchar(8)), cast(? as int)) "t" ("id", "version", "faction_id", "name", "description", "item", "amount", "status", "legacy_id")) "t" on "currencies_currency"."id" = "t"."id" when matched and ("currencies_currency"."id" = cast(? as varchar(36)) and "currencies_currency"."version" = cast(? as int)) then update set "currencies_currency"."faction_id" = ?, "currencies_currency"."name" = ?, "currencies_currency"."description" = ?, "currencies_currency"."item" = ?, "currencies_currency"."amount" = ?, "currencies_currency"."status" = ?, "currencies_currency"."legacy_id" = ?, "currencies_currency"."version" = ? when not matched then insert ("id", "version", "faction_id", "name", "description", "item", "amount", "status", "legacy_id") values ("t"."id", "t"."version", "t"."faction_id", "t"."name", "t"."description", "t"."item", "t"."amount", "t"."status", "t"."legacy_id")]; (Message 23505 not found); SQL statement:
merge into "currencies_currency" using (select "t"."id", "t"."version", "t"."faction_id", "t"."name", "t"."description", "t"."item", "t"."amount", "t"."status", "t"."legacy_id" from (select cast(? as varchar(36)), cast(? as int), cast(? as varchar(36)), cast(? as varchar(256)), cast(? as varchar(4096)), cast(? as blob), cast(? as int), cast(? as varchar(8)), cast(? as int)) "t" ("id", "version", "faction_id", "name", "description", "item", "amount", "status", "legacy_id")) "t" on "currencies_currency"."id" = "t"."id" when matched and ("currencies_currency"."id" = cast(? as varchar(36)) and "currencies_currency"."version" = cast(? as int)) then update set "currencies_currency"."faction_id" = ?, "currencies_currency"."name" = ?, "currencies_currency"."description" = ?, "currencies_currency"."item" = ?, "currencies_currency"."amount" = ?, "currencies_currency"."status" = ?, "currencies_currency"."legacy_id" = ?, "currencies_currency"."version" = ? when not matched then insert ("id", "version", "faction_id", "name", "description", "item", "amount", "status", "legacy_id") values ("t"."id", "t"."version", "t"."faction_id", "t"."name", "t"."description", "t"."item", "t"."amount", "t"."status", "t"."legacy_id") [23505-214]
com.dansplugins.factionsystem.shadow.org.jooq.exception.DataAccessException: SQL [merge into "currencies_currency" using (select "t"."id", "t"."version", "t"."faction_id", "t"."name", "t"."description", "t"."item", "t"."amount", "t"."status", "t"."legacy_id" from (select cast(? as varchar(36)), cast(? as int), cast(? as varchar(36)), cast(? as varchar(256)), cast(? as varchar(4096)), cast(? as blob), cast(? as int), cast(? as varchar(8)), cast(? as int)) "t" ("id", "version", "faction_id", "name", "description", "item", "amount", "status", "legacy_id")) "t" on "currencies_currency"."id" = "t"."id" when matched and ("currencies_currency"."id" = cast(? as varchar(36)) and "currencies_currency"."version" = cast(? as int)) then update set "currencies_currency"."faction_id" = ?, "currencies_currency"."name" = ?, "currencies_currency"."description" = ?, "currencies_currency"."item" = ?, "currencies_currency"."amount" = ?, "currencies_currency"."status" = ?, "currencies_currency"."legacy_id" = ?, "currencies_currency"."version" = ? when not matched then insert ("id", "version", "faction_id", "name", "description", "item", "amount", "status", "legacy_id") values ("t"."id", "t"."version", "t"."faction_id", "t"."name", "t"."description", "t"."item", "t"."amount", "t"."status", "t"."legacy_id")]; (Message 23505 not found); SQL statement:
merge into "currencies_currency" using (select "t"."id", "t"."version", "t"."faction_id", "t"."name", "t"."description", "t"."item", "t"."amount", "t"."status", "t"."legacy_id" from (select cast(? as varchar(36)), cast(? as int), cast(? as varchar(36)), cast(? as varchar(256)), cast(? as varchar(4096)), cast(? as blob), cast(? as int), cast(? as varchar(8)), cast(? as int)) "t" ("id", "version", "faction_id", "name", "description", "item", "amount", "status", "legacy_id")) "t" on "currencies_currency"."id" = "t"."id" when matched and ("currencies_currency"."id" = cast(? as varchar(36)) and "currencies_currency"."version" = cast(? as int)) then update set "currencies_currenc...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes Dans-Plugins/Currencies#191

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/Dans-Plugins/Currencies/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error when creating a currency Fix duplicate currency name check when using --rename flag Dec 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants