ash-project / ash_double_entry

A customizable double entry bookkeeping system backed by Ash resources.
MIT License
15 stars 4 forks source link

Error Creating Transfer After Upgrading from Version 0.2.4 to 1.0.6 – PostgreSQL ambiguous_function Operator Issue #66

Open zeadhani opened 3 weeks ago

zeadhani commented 3 weeks ago

Issue Summary

When creating a transfer after upgrading from version 0.2.4 to 1.0.6, an error occurs during the operation. The PostgreSQL error ambiguous_function appears, indicating that an operator is not unique, with the hint suggesting the need for explicit type casts.

Steps to Reproduce

  1. Upgrade ash_double_entry from version 0.2.4 to 1.0.6.
  2. Run the transfer creation process using the following context: -> Transfer involves inserting into or updating the balances table.
  3. Encounter an error during the operation with the following debug logs:

[debug] QUERY ERROR source="balances" db=0.0ms UPDATE "balances" AS b0 SET "balance" = (CASE ... ) WHERE ... ** (Postgrex.Error) operator is not unique: - unknown Hint: Could not choose a best candidate operator. You might need to add explicit type casts.

Observed Behavior

The transfer creation fails with an ambiguous_function error in PostgreSQL.

Expected Behavior

The transfer should be created without any errors, and the balances table should update correctly.

Additional Details

Troubleshooting Done

image

zachdaniel commented 3 weeks ago

What specific ash, ash_postgres and ash_sql versions are you using?

zachdaniel commented 3 weeks ago

Also ash_money

zachdaniel commented 3 weeks ago

Please make sure you're on the latest of all of them.

zeadhani commented 3 weeks ago

I am using the following versions, all of which are updated:

•   ash_postgres: ~> 2.4.12
•   ash_sql: ~> 0.2.38
•   ash_double_entry: ~> 1.0.6
•   ash_money: ~> 0.1.13
•   ex_money_sql: ~> 1.11
zachdaniel commented 3 weeks ago

I've made a small change in main that may help, but if not I will have to look into this next week. Please try it out and let me know.

zeadhani commented 3 weeks ago

Thank you for the quick response and update! I tried the change, but now I’m getting the following error: ** (Postgrex.Error) ERROR 42725 (ambiguous_function) operator is not unique: + unknown

Please let me know when it’s fixed or if there’s an issue on my end that I should address. Appreciate your help!

zachdaniel commented 3 weeks ago

🤔 something is definitely strange there. I'm not seeing the same error in my own application. Can you please create a reproduction? Have you applied the relevant ash_money migrations? I think there may be a set up issue somewhere along those lines.

zeadhani commented 3 weeks ago

I’ll double-check those migrations tomorrow morning and provide a quick update. 🙇‍♂️

zachdaniel commented 3 weeks ago

I actually found something that I think may be the cause. It requires a fix both in Ash and AshMoney. I will push the fix up to main of both and you can try it :)

It fixes a different issue that I noticed, but seems "adjacent" to this one :)

zachdaniel commented 3 weeks ago

Please give those packages (in main) a try and LMK. If not, a reproduction will be necessary.

zeadhani commented 3 weeks ago

Thanks for looking into this! I pulled all the packages from the main and re-ran all the migrations from scratch, but the error still exists.

image
zeadhani commented 3 weeks ago
image
zachdaniel commented 3 weeks ago

Okay, please provide a small reproduction project so I can diagnose further

zeadhani commented 3 weeks ago

Will do