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

Prevent loading association when include_data is set to false #1710

Merged
merged 1 commit into from
May 25, 2016

Conversation

groyoh
Copy link
Member

@groyoh groyoh commented Apr 29, 2016

Purpose

Fixes #1707.

Changes

Do not call read_attribute_for_serialization when include_data is set to false.

@groyoh groyoh added the S: Bug label Apr 29, 2016
@NullVoxPopuli
Copy link
Contributor

gasp! those errors!
didyou/can you rebase? I think some jruby fixes were merged recently

@groyoh
Copy link
Member Author

groyoh commented Apr 29, 2016

Yeah, already rebased to latest master. Not sure what happens here, I can't reproduce it locally.

@NullVoxPopuli
Copy link
Contributor

what if you uninstall the sqlite3 adapter? - it's complaining that it's not installed.

While it's not a dep of ams, it is for the ActiveRecord tests

@groyoh
Copy link
Member Author

groyoh commented Apr 29, 2016

I don't have sqlite3 adapter installed locally.

@NullVoxPopuli
Copy link
Contributor

even weirder

@groyoh
Copy link
Member Author

groyoh commented Apr 29, 2016

Actually, sqlite3 adapter comes out of the box with AR. So THAT's even weirder.

block_value
elsif @_include_data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when is @_include_data present?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the question but it is set to true by default so includes the relationship data by default. The point of the PR is to prevent calling the relationship if include_data is set to false.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aight, I guess we'll document _include_data at a later date

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already documented but the behavior added in this PR is not though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NullVoxPopuli please don't merge code with missing else clauses. I was going to say it was a bug and raise a ❗ but then I realized that it was the feature of the PR. 😱 :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense.

@NullVoxPopuli
Copy link
Contributor

woo! LGTM 🍕

@NullVoxPopuli
Copy link
Contributor

@groyoh do you want to add a changelog entry?

@groyoh
Copy link
Member Author

groyoh commented May 24, 2016

@NullVoxPopuli will do.

@groyoh
Copy link
Member Author

groyoh commented May 24, 2016

@NullVoxPopuli added the CHANGELOG.

@NullVoxPopuli
Copy link
Contributor

thanks! merging!

@NullVoxPopuli NullVoxPopuli merged commit a701777 into rails-api:master May 25, 2016
@YoranBrondsema
Copy link

YoranBrondsema commented Jun 4, 2016

@NullVoxPopuli Although small, this PR has a very big impact for the performance of our app. Would it be possible to bump the version so that the latest version includes this? Thanks!

@NullVoxPopuli
Copy link
Contributor

you can specify a commit hash in your gemfile. :-)

we aren't ready to bump the version quite yet.

@YoranBrondsema
Copy link

I know that :-). I was just wondering if a patch update was possible so that everyone can benefit from this change now, but I will resort to specifying the commit.

@groyoh groyoh deleted the fix_1707 branch June 4, 2016 13:40
@sandstrom
Copy link

This is a great addition, but wouldn't it make more sense if this was an option:

has_one :blog, :include_data => false do |serializer|
  serializer.cached_blog
end

Instead of being set from within the block? Or have I missed something?

@@ -158,10 +157,16 @@ def test_relationship_meta
end

def test_relationship_not_including_data
@author.define_singleton_method(:read_attribute_for_serialization) do |attr|
fail 'should not be called' if attr == :blog
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test needs to change as well. It shouldn't be raising a runtime error and is hard to read and why do we even need the define_singleton_method?

😦

Copy link
Member

@bf4 bf4 Aug 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't understand why this test was changed, why blog was removed from the setup

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, this test file is basically garbage. See #1857 would be better to do an 'integration' test

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.

None yet

5 participants