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

Fix json autoload #16148

Merged
merged 2 commits into from
Jul 29, 2014
Merged

Fix json autoload #16148

merged 2 commits into from
Jul 29, 2014

Conversation

chancancode
Copy link
Member

When requiring the json core_ext, we are relying on AS's autoload to load the json/encoding file to avoid a circular dependency. Here we are incorrectly referencing the delegated config which is not yet available until we load json/encoding.

The fix is pretty straight forward, but adding a regression test for this is tricky. @jeremy wdyt about the test I added here? It works, but have some doubts about it. Do you have better suggestions?

Fixes #16131

@chancancode chancancode added this to the 4.1.5 milestone Jul 12, 2014
@chancancode chancancode self-assigned this Jul 12, 2014
@chancancode
Copy link
Member Author

(In case anyone wonders – the reason Oj could trigger this issue is that it calls as_json without calling to_json. In other usage, the entry point is usually to_json, which triggers the autoload, so by the time it calls as_json the delegation is already setup.)

`Time#as_json`, `Date#as_json` and `DateTime#as_json` incorrectly depends on a
delegation that is set up in `active_support/json/encoding`. We cannot simply
require that file in `core_ext/object/json` because it would cause a circular
dependency problem (see #12203 for background). We should instead rely on AS's
autoload to load that file for us on-demand.

To trigger autoload correctly, we need to reference the `AS::JSON::Encoding`
constant instead of using the delegated version.

Fixes #16131.
@chancancode
Copy link
Member Author

@jeremy @tenderlove @rafaelfranca I'm merging this so that the fix can go out with 4.1.5. I'll take suggestions/feedback if you think the test case can be improved further but that probably shouldn't block the release 😁

chancancode added a commit that referenced this pull request Jul 29, 2014
@chancancode chancancode merged commit 540bc3d into master Jul 29, 2014
chancancode added a commit that referenced this pull request Jul 29, 2014
Fix json autoload
Conflicts:
	activesupport/CHANGELOG.md
@rafaelfranca rafaelfranca deleted the fix_json_autoload branch July 29, 2014 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActiveSupport(4.1 or above) raise error when creating JSON data with MultiJson and Oj.
1 participant