Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With oj gem - ActionView::Template::Error Infinity not allowed in JSON #2486

Closed
hhff opened this issue Jan 4, 2018 · 4 comments
Closed

With oj gem - ActionView::Template::Error Infinity not allowed in JSON #2486

hhff opened this issue Jan 4, 2018 · 4 comments
Labels
type:bug Error, flaw or fault

Comments

@hhff
Copy link

hhff commented Jan 4, 2018

Steps to reproduce

Load an order from the Solidus Checkouts API with a Line Item Variant with track_inventory: false, using the following responder:

respond_with(@order, default_template: 'spree/api/orders/show', status: 200)

Actual behavior

The API will throw: ActionView::Template::Error Infinity not allowed in JSON.

Source of the issue:

json.total_on_hand(variant.total_on_hand)

As it corresponds to:

Expected behavior

I would expect that in the case track_inventory is false, the _small.json.jbuilder template would not include the total_on_hand attribute.

System configuration

Solidus Version: 2.4.2

@jhawthorn
Copy link
Contributor

I wasn't able to reproduce this, maybe I missed something.

I added a spec to the orders_controller (which renders the same partials and is easier to test), and it rendered without error.

jhawthorn@5ae69a7

@hhff
Copy link
Author

hhff commented Jan 8, 2018 via email

@jhawthorn
Copy link
Contributor

Yep! oj seems to be the culprit

@jhawthorn jhawthorn changed the title Checkouts API should not attempt to serialize Float::INFINITY With oj gem - ActionView::Template::Error Infinity not allowed in JSON Jan 10, 2018
@jhawthorn jhawthorn added the type:bug Error, flaw or fault label Jan 10, 2018
@SebAshton
Copy link
Contributor

Anyone else stumbling into this error, the solution is to set the following in an initializer:

# https://github.com/ohler55/oj/blob/master/pages/Options.md#nan-symbol
# Fixes issue with Infinity in JSON

require 'oj'

Oj.default_options = {
  mode: :compat,
  nan: :huge
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Error, flaw or fault
Projects
None yet
Development

No branches or pull requests

3 participants