better_params icon indicating copy to clipboard operation
better_params copied to clipboard

existing atoms

Open leoamigood opened this issue 3 years ago • 2 comments

I tried your library, thank you for developing it, looks interesting.

One issue i found is that sometimes String.to_existing_atom will fail and we would loose some keys, i think we need to handle this case in rescue block, for example as String.to_atom

leoamigood avatar Aug 31 '22 19:08 leoamigood

This should not be possible as atoms are never garbage collected by the Erlang VM.

The best way to use better_params is to use atom literals in the codebase, which ensure that those params are atomized. E.g.:

params.id
# or
params[:some][:nested][:value]

# instead of
params[:"dynamic_#{key}"]

Can you provide more details about your Elixir & Erlang version, OS, and ideally an MCVE so I can try to reduce it?

sheharyarn avatar Aug 31 '22 20:08 sheharyarn

Hello sheharyarn, I just meet the same problem.

I write a POST API with nested params in body params. When send request, it lost params casually inside nested struct. I replaced to_existing_atom by to_atom, it solved.

lxedge avatar Sep 06 '22 20:09 lxedge