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
Likely either chunk_no or topic_id are nil when the code is ran.
3
Popular in Questions
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database.
Dep...
New
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”:
14:57:30.512 [warn] ...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Hey,
I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
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
Other popular topics
Manning 2016 Halloween weekend sale via Deal of the Day
Friday, October 28 - Half off all MEAPs - code WM102816LT
Saturday, October 29 ...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
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
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New
Hey :wave:t3: Elixir community,
I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New







