String- vs atom-keyed maps produced by phx.gen.html

I’m confused by the phx.gen.html-generated tests (with phoenix master as of a few days ago, at 823b27bc); they sometimes call the context with string-keyed maps (from the controller tests), and sometimes atom-keyed (from the context test). Real calls arrive string-keyed, I checked.

This isn’t a new question - I found this issue from 2015 and this PR for it but both were closed without changes.

I’m working on app that tracks stock trades. I’ve got a Portfolio context with Transaction and Company schemas; Transaction belongs_to Company, and Company has a unique symbol field. The params for transaction will come in with %{“company” => “SYM”}, and I want the context to find or create the company with that symbol and replace the company parameter in the params map before passing it to Transaction.changeset. Based on the generated context tests, I wrote this code to work with atom-keyed maps, but when I started to address the failing generated schema tests, I found that they’re using string-keyed maps.

I could write my context additions to work both ways, maybe by converting atom-keyed maps in the context if necessary, but it seems more appropriate to convert the atom-keyed maps in the tests… and if that’s right, shouldn’t the generated tests do that? Or, maybe I’m not thinking about this the way I’m supposed to – is there a better approach? (Thanks!)

1 Like