sreeramvenkat
Error when using Ecto to check presence of record: (ArgumentError) comparison with nil is forbidden as it is unsafe
Hello !,
I am unable to fix below error I face in Ecto.
Code:
39 def insert_or_get_record(attrs) do
40 chunk_no = Map.get(attrs, :chunk_no)
41 topic_id = Map.get(attrs, :topic_id)
42
43
44 query =
45 from c in __MODULE__,
46 where: c.chunk_no == ^chunk_no and c.topic_id == ^topic_id,
47 limit: 1
48
49 record = Repo.one(query)
50 if record do
51 {:ok, record}
52 else
53 cs = changeset(%__MODULE__{}, attrs)
54 Repo.insert(cs)
55 end
56
57 end
This is the error I get
** (ArgumentError) comparison with nil is forbidden as it is unsafe. If you want to check if a value is nil, use is_nil/1 instead
(ecto 3.11.2) lib/ecto/query/builder.ex:1069: Ecto.Query.Builder.not_nil!/1
(thiruvinai 0.1.0) lib/thiruvinai/entities/chunk.ex:45: Thiruvinai.Chunk.insert_or_get_record/1
(thiruvinai 0.1.0) lib/thiruvinai/utils/load_util.ex:74: Thiruvinai.LoadUtil.load_questions/1
(thiruvinai 0.1.0) lib/thiruvinai/utils/load_util.ex:39: Thiruvinai.LoadUtil.process_json_file/2
(thiruvinai 0.1.0) lib/thiruvinai/utils/load_util.ex:26: Thiruvinai.LoadUtil.process_json_file/1
(elixir 1.15.5) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
I find this baffling since I do not perform any nil check.
Kindly help !
Thank you !
Sreeram
Most Liked
dimitarvp
Last Post!
sreeramvenkat
Popular in Questions
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
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
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Other popular topics
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
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
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









