Skip to content

Cannot create new record with valid attributes #10

@jesster2k10

Description

@jesster2k10

I'm running the latest versions of the Graphiti toolkit on Rails 6.2 and I'm unable to create a new record with my API, given valid attributes. An error is thrown when there are no validation errors like so:

#<NoMethodError: undefined method `[]' for nil:NilClass>

which points to like 42 in this file https://github.com/graphiti-api/graphiti_errors/blob/master/lib/graphiti_errors/validation/serializer.rb

          details = if Rails::VERSION::MAJOR >= 5
            object.errors.details.find { |k, v| k == attribute }[1]
          end

When there are validation errors, the NoMethodError is not thrown. Only when the record is valid.

Request:

POST localhost:3000/api/v1/accounts

{
	"data": {
		"type": "accounts",
		"attributes": {
			"name": "Savings Account",
			"account_type": "savings",
			"currency": "eur"
		}
	}
}

Response:

"meta": {
        "__details__": {
          "exception": "#<NoMethodError: undefined method `[]' for nil:NilClass>",
          "traces": {
            "Application Trace": [
              {
                "exception_object_id": 70175924115520,
                "id": 24,
                "trace": "app/controllers/accounts_controller.rb:20:in `create'"
              }
            ],
            "Framework Trace": [
              {
                "exception_object_id": 70175924115520,
                "id": 0,
                "trace": "graphiti_errors (1.1.1) lib/graphiti_errors/validation/serializer.rb:42:in `block in each_error'"
              },
              //... irrelevant back trace
           ]
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions