sheerlox

sheerlox

Array type "empty_values" cannot remove all empty values

I have a Phoenix Live component that renders multiple string inputs to match the {:array, :string} Ash type:

Previously my codebase was using Ecto, and I’ve found a difference in the way empty_values works between the two: in Ecto, all empty values found in empty_values/0 are removed from the list, whereas in Ash the empty_values constraint is matched directly against the list.

My first guess was to declare my resource attribute as follows:

attribute :skills, {:array, :string}, constraints: [empty_values: [[nil], [""]]]

which works fine if the user does not fill the default blank line on the form.

However, if another blank line is added, or if blank lines are mixed with filled ones, they are inserted as nil in the database:

I’m looking for a way to trim these values in the same way I would in Ecto, but from reading the documentation and reading the code, it doesn’t seem to me like it’s possible.

I’d like to know if there’s a motivation behind this design choice, or if a discussion & PR to make that possible could be entertained (if so, I’d be more than happy to contribute to this amazing framework :heart:).

Thanks!

Marked As Solved

zachdaniel

zachdaniel

Creator of Ash

I would say that we should move the is_nil check to after applying constraints to the inner items, primarily because types could even theoretically do the reverse, taking a nil item and casting it to a value.

I also wouldn’t personally consider it a breaking change, but rather a bug fix. If nil_items?: false can still produce an array with nil items, that counts as a bug in my book :slight_smile:

Please open an issue for these so we can make sure to address them (or of course a PR :slight_smile: )

Also Liked

Last Post!

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement