Ash.bulk_create seems to return success when the insert fails

I have a resource that has an atom attribute that can’t be nil:

    attribute :cbsa_category, :atom do
      allow_nil? false

      constraints one_of: [:metropolitan, :micropolitan, :unknown]
    end

Here is that resource create action:

    create :create_in_temp do
      change fn changeset, _ ->
        Ash.Changeset.set_context(changeset, %{data_layer: %{schema: "temp"}})
      end
    end

When i try to insert a bunch of rows to that resource using bulk_create and one of the data contains a nil cbsa_category field, the query itself will rollback, but Ash will return no error:

Pacman.Markets.bulk_create(a, Pacman.Markets.CBSABuyBox, :create_in_temp, return_records?: false, return_errors?: true)

[debug] QUERY OK db=0.3ms idle=1450.9ms
begin []
[debug] QUERY ERROR source="cbsa_buy_boxes" db=0.9ms
INSERT INTO "temp"."cbsa_buy_boxes" ("id","inserted_at","updated_at","entity_id","cbsa_code","cbsa_category","cbsa_name","financing_types","maximum_buy_price","maximum_property_bathrooms","maximum_property_bedrooms","maximum_property_building_area","maximum_property_lot_square_feet","maximum_property_year_built","maximum_sell_price","minimum_buy_price","minimum_property_bathrooms","minimum_property_bedrooms","minimum_property_building_area","minimum_property_lot_square_feet","minimum_property_year_built","minimum_sell_price","property_types","strategies","transactions_ids") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25),($26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50),($51,$52,$53,$54,$55,$56,$57,$58,$59,$60,$61,$62,$63,$64,$65,$66,$67,$68,$69,$70,$71,$72,$73,$74,$75),($76,$77,$78,$79,$80,$81,$82,$83,$84,$85,$86,$87,$88,$89,$90,$91,$92,$93,$94,$95,$96,$97,$98,$99,$100),($101,$102,$103,$104,$105,$106,$107,$108,$109,$110,$111,$112,$113,$114,$115,$116,$117,$118,$119,$120,$121,$122,$123,$124,$125),($126,$127,$128,$129,$130,$131,$132,$133,$134,$135,$136,$137,$138,$139,$140,$141,$142,$143,$144,$145,$146,$147,$148,$149,$150) [...]
%Ash.BulkResult{
  status: :success,
  errors: [],
  records: nil,
  notifications: [],
  error_count: 0
}
[debug] QUERY OK db=0.3ms
rollback []

I’m using Ash version 2.20.3 and ash_postgres version 1.5.22

Hmm…that is definitely strange…it must be the rollback case? Can you open an issue on ash_postgres? Will look into it soon.

Done: Ash.bulk_create returns success when the insert fails and rollback · Issue #226 · ash-project/ash_postgres · GitHub

Hey @zachdaniel , I know you are very busy right now with the Ash 3.0 RC, but did you took a look into this issue? Since it is a silent issue, I believe this could be affecting other people besides me but they are not even realizing it since there will be no error being triggered.

Yes, I actually started looking into it about 30 minutes ago. Should have a fix soon.

1 Like

Should be fixed in Ash 2.21.3

1 Like