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

For recursive or cyclic blueprints, halt after 10 levels by default #24

Merged
merged 2 commits into from
Jun 27, 2024

Conversation

jhollinger
Copy link
Contributor

@jhollinger jhollinger commented Jun 12, 2024

A fix for #13, where we get infinite recursion when a blueprint has an association to self, or when it's part of a cycle. Now it will halt preloading after 10 cycles. If that's not enough, it can be increased:

class CategoryBlueprint < Blueprinter::Base
  field :name
  association :children, blueprint: self, max_recursion: 20
end

@jhollinger jhollinger requested a review from a team as a code owner June 12, 2024 16:22
@jhollinger jhollinger force-pushed the fix-recursive-blueprint branch from 03f5f48 to e927ff7 Compare June 12, 2024 16:24
@jhollinger jhollinger force-pushed the fix-recursive-blueprint branch from e927ff7 to c9b0ced Compare June 12, 2024 20:04
@jhollinger jhollinger force-pushed the fix-recursive-blueprint branch 6 times, most recently from a9cc576 to a367138 Compare June 25, 2024 18:56
@jhollinger jhollinger changed the title If there's a blueprint that renders itself, halt after one level. If there's a blueprint that renders itself, halt after 10 levels by default Jun 25, 2024
@jhollinger jhollinger force-pushed the fix-recursive-blueprint branch from a367138 to 8e23ecc Compare June 25, 2024 21:42
lessthanjacob
lessthanjacob previously approved these changes Jun 26, 2024
@@ -42,7 +42,7 @@ def initialize(&log_proc)
def pre_render(object, blueprint, view, options)
if object.is_a?(ActiveRecord::Relation) && object.before_preload_blueprint
from_code = object.before_preload_blueprint
from_blueprint = Preloader.preloads(blueprint, view, object.model)
from_blueprint = Preloader.preloads(blueprint, view, model: object.model)
Copy link
Contributor

Choose a reason for hiding this comment

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

non-blocking: Worth making all of these kwargs if we're changing model?

lib/blueprinter-activerecord/preloader.rb Outdated Show resolved Hide resolved
@jhollinger jhollinger force-pushed the fix-recursive-blueprint branch from 8e23ecc to ac138a0 Compare June 26, 2024 18:15
@jhollinger jhollinger changed the title If there's a blueprint that renders itself, halt after 10 levels by default For recursive or cyclic blueprints, halt after 10 levels by default Jun 26, 2024
@jhollinger jhollinger force-pushed the fix-recursive-blueprint branch from ac138a0 to ba94307 Compare June 26, 2024 18:26
@jhollinger jhollinger requested a review from lessthanjacob June 26, 2024 18:32
@jhollinger jhollinger merged commit b83e659 into main Jun 27, 2024
7 checks passed
@jhollinger jhollinger deleted the fix-recursive-blueprint branch June 27, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants