cloedu87

cloedu87

Hi There,

On the mission to find a ash friendly way to add versioning to my project. I found ash-paper-trail.
My requirements were:

  • postgres compatible
  • no additional database extensions
  • testing friendly (no workaround to run tests)
  • support to add versioning to single resources instead of all tables
  • option to only store the attributes which changed

after browsing a bit through the forum I found this post which gave me a great idea of whats possible and I started using ash-paper-trail because it ticks all the boxes.

After setting up things and migrating the database, I faced errors while executing my tests:

** (Ash.Error.Invalid) Input Invalid

     * Invalid value provided for version_source_id: got invalid prefixed term.

     "rec_02vbruyKluKnzDyCkFExo8"
     
     code: assert {:ok, %Record{} = _record} = Record.create(attrs)
     stacktrace:
       (ash 2.18.2) lib/ash/api/api.ex:2711: Ash.Api.unwrap_or_raise!/3
       (ash_paper_trail 0.1.0) lib/resource/changes/create_new_version.ex:93: AshPaperTrail.Resource.Changes.CreateNewVersion.build_notifications/2
       (ash_paper_trail 0.1.0) lib/resource/changes/create_new_version.ex:22: anonymous fn/2 in AshPaperTrail.Resource.Changes.CreateNewVersion.create_new_version/1
...

then I checked my resource definition:

...
  use Ash.Resource,
    data_layer: AshPostgres.DataLayer,
    extensions: [
      AshUUID,
      AshPaperTrail.Resource
    ]
...
  attributes do
    uuid_attribute :id, prefix: "rec"
    attribute :name, :string
    attribute :description, :string
    timestamps private?: false, writable?: false
  end

  paper_trail do
    change_tracking_mode :changes_only
    store_action_name? true
    ignore_attributes [:inserted_at, :updated_at]
  end
...

And I was wondering if the use of AshUUID and the prefixed primary key definition leads to the fact that I can’t use ash-paper-trail at all or if I missed the one hint to make it work in this case?
It would be really a shame if it would not work, because it’s such a smooth and nice integration compared to other solutions.

All the Best

Showing Posts 1 to 10

zachdaniel

zachdaniel

Creator of Ash

I think I see the issue. We aren’t properly copying the type of the attribute that we use for version_source_id. Let me see what I can do.

zachdaniel

zachdaniel

Creator of Ash

okay, can you try out the main branch of ash_paper_trail?

cloedu87

cloedu87 OP

oh wow… sure… I’ll try…

cloedu87

cloedu87 OP

using {:ash_paper_trail, github: "ash-project/ash_paper_trail", branch: "main"}: it seems to be still the same problem.

thx anyway for jumping in so quickly! :slight_smile: well appriciated.

the resource I use, is very minimal, so from that side, no side effects should be expected:

defmodule App.Records.TestResource do
  @moduledoc false

  use Ash.Resource,
    data_layer: AshPostgres.DataLayer,
    extensions: [
      AshUUID,
      AshPaperTrail.Resource
    ]

  attributes do
    uuid_attribute :id, prefix: "baa"
    attribute :name, :string
    attribute :description, :string
    timestamps private?: false, writable?: false
  end

  paper_trail do
    change_tracking_mode :changes_only
    store_action_name? true
    ignore_attributes [:inserted_at, :updated_at]
  end

  actions do
    defaults [:create, :read, :update, :destroy]
  end

  code_interface do
    define_for App.Records
    define :create
    define :read
    define :update
    define :destroy
  end

  postgres do
    table "test_resources"
    repo App.Repo
  end
end

Best, C.

cloedu87

cloedu87 OP

checking the code you changed…

        relationships do
          belongs_to :version_source, unquote(module) do
            destination_attribute(unquote(destination_attribute))
            allow_nil?(false)
            attribute_writable?(true)
            source_attribute(:version_source_id) # your change...
          end

… shouldn’t there be a attribute_type(first_pkey_attr_type) within the belongs_to definition to use the correct type for the related resource as well ?

zachdaniel

zachdaniel

Creator of Ash

This would configure that attribute:

          unless unquote(is_nil(first_pkey_attr)) do
             attribute :version_source_id, unquote(Macro.escape(first_pkey_attr_type)) do
               constraints unquote(Macro.escape(first_pkey_attr_constraints))
               allow_nil? false
             end
           end
zachdaniel

zachdaniel

Creator of Ash

I’m surprised you have the same issue…is there a different stack trace?

zachdaniel

zachdaniel

Creator of Ash

@rgraff may have an idea. As far as I can tell, the problem centers around incorrect constraints for that attribute. However, it could also be something that uuid_attribute is doing strange, I’m not familiar with the inner workings of it.

cloedu87

cloedu87 OP

yes it’s exactly the same stack trace. but I can try searching in the direction of uuid_attribute’s behavior, maybe I can find out something in this corner…

Thanks anyway :pray:

rgraff

rgraff

Ash Core Team

I’m pretty sure Zach’s on the right track. Since I’m not familiar with AshUUID, so this might take some trial and error.

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews