Giter Site home page Giter Site logo

better_params's People

Contributors

phyllisstein avatar sheharyarn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

yammine lxedge

better_params's Issues

Crashes on File Uploads

When the web request contains a %Plug.Upload{} struct, it crashes the process with a Protocol.UndefinedError:

[error] #PID<0.737.0> running MyApp.Endpoint terminated
Server: localhost:5000 (http)
Request: POST /some/server/path
** (exit) an exception was raised:
    ** (Protocol.UndefinedError) protocol Enumerable not implemented for %Plug.Upload{content_type: "image/jpeg", filename: "123456789.jpg", path: "/var/folders/rr/1l6bz6rd6tq_h70m1scxy51m0000gn/T//plug-1502/multipart-837302-850377-2"}
        (elixir) lib/enum.ex:1: Enumerable.impl_for!/1
        (elixir) lib/enum.ex:116: Enumerable.reduce/3
        (elixir) lib/enum.ex:1767: Enum.reduce/3
        lib/better_params.ex:79: anonymous fn/2 in BetterParams.symbolize_keys/1
        (stdlib) lists.erl:1263: :lists.foldl/3
        lib/better_params.ex:68: BetterParams.symbolize_merge/1
        lib/better_params.ex:36: BetterParams.call/2
        ...

Recommendation for usage with Ecto?

Hey there! I really love the idea of this module, preferring the feel of atom keys by a mile, but it's creating some trouble with Ecto. In cases where I just want to dump a whole mess of params into a cast call, Ecto throws an error on encountering mixed keys:

    ** (Ecto.CastError) expected params to be a map with atoms or string keys, got a map with mixed keys: %{:author_email => "[email protected]", :author_name => "Daniel P. Shannon", :body => "Foo bar baz quux.", :title => "Foo Bar Baz Quux", "author_email" => "[email protected]", "author_name" => "Daniel P. Shannon", "body" => "Foo bar baz quux.", "title" => "Foo Bar Baz Quux"}
        (ecto) lib/ecto/changeset.ex:542: anonymous fn/3 in Ecto.Changeset.convert_params/1
        (ecto) lib/ecto/changeset.ex:537: Ecto.Changeset.convert_params/1
        (ecto) lib/ecto/changeset.ex:442: Ecto.Changeset.do_cast/7
        (poppins_schema) lib/poppins_schema/crm/query.ex:16: PoppinsSchema.CRM.Query.submit_changeset/2
        (poppins_schema) lib/poppins_schema/crm/crm.ex:7: PoppinsSchema.CRM.submit_query/1
        (poppins_web) lib/poppins_web/controllers/crm/query_controller.ex:9: PoppinsWeb.CRM.QueryController.create/2
        (poppins_web) lib/poppins_web/controllers/crm/query_controller.ex:1: PoppinsWeb.CRM.QueryController.action/2

Frankly this strikes me as a little silly of Ecto, but I was curious whether there was a way to either drop the duplicate fallback strings or get around the cast issue without explicitly rebuilding the params map for every endpoint.

(Sorry for a bit of a StackOverflow-y question, but I guess it's part feature request since I'd love to just omit the strings. ๐Ÿ˜ฌ )

existing atoms

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

Use String.to_existing_atom to avoid leaking.

A quick look at your code, seems like using your ExUtils to convert any request parameter into atoms is a bad idea (unless you used something like String.to_existing_atom), otherwise it would be really easy to create something that generates random parameter keys and quickly fills your atom table as they are never freed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.