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

JBuilder 2.11.3: "NoMethodError Exception: undefined method empty? for PG::Result" #516

Closed
jtannas opened this issue Nov 17, 2021 · 7 comments · Fixed by #524
Closed

JBuilder 2.11.3: "NoMethodError Exception: undefined method empty? for PG::Result" #516

jtannas opened this issue Nov 17, 2021 · 7 comments · Fixed by #524

Comments

@jtannas
Copy link

jtannas commented Nov 17, 2021

When rendering records returned by SQL JBuilder fails with

NoMethodError Exception: undefined method `empty?` for PG::Result

Simplified example:

irb(main):001:0> query_result = ActiveRecord::Base.connection.execute('SELECT * FROM users LIMIT 1')
=> #<PG::Result:0x00005594547c1120 status=PGRES_TUPLES_OK ntuples=1 nfields=31 cmd_tuples=1>
irb(main):002:0> query_result.empty?
(irb):2:in `<main>': undefined method `empty?' for #<PG::Result:0x00005594547c1120 status=PGRES_TUPLES_OK ntuples=1 nfields=31 cmd_tuples=1> (NoMethodError)

Ruby Version: 3.0.2p107
Jbuilder Gem Version: 2.11.3
PG Gem Version: 1.2.3

@tf
Copy link
Contributor

tf commented Nov 22, 2021

Introduced here in #501. Related to #514.

@dhh
Copy link
Member

dhh commented Dec 16, 2021

cc @yuki24

@yuki24
Copy link
Contributor

yuki24 commented Dec 17, 2021

#524 should address this issue.

@dhh dhh closed this as completed in #524 Dec 17, 2021
@yuki24
Copy link
Contributor

yuki24 commented Dec 17, 2021

Unfortunately there is a little incompatibility introduced by #501. I have removed the #empty? call, but ActionView's CollectionRenderer requires #length or #size to be implemented in Rails 6.1.

@jtannas @dhh I wonder if this is okay...

@dhh
Copy link
Member

dhh commented Dec 18, 2021

Not sure I fully understand the issue? The enumerable passed in much implement #length or #size?

@jtannas
Copy link
Author

jtannas commented Dec 18, 2021

Unfortunately this is a little incompatibility Introduced by #501. I have removed the #empty? call, but ActionView's CollectionRenderer requires #length or #size to be implemented in Rails 6.1.

yeah, I'm seeing that in the test run when upgrading to 2.11.4 that it's still failing when attempting to render a PG::Result.

     Failure/Error:
       json.partial!(
         'sample_partial',
         collection: @sample_pg_result,
         as: :row,
       )

     ActionView::Template::Error:
       undefined method `size' for #<PG::Result:0x0000563f594901a8 status=PGRES_TUPLES_OK ntuples=0 nfields=7 cmd_tuples=0>
       Did you mean?  fsize

Edit: looks like there's some relevant discussion in #514 about how before it would work on anything implementing Enumerable but now additional methods are required
#514 (comment)

@yuki24
Copy link
Contributor

yuki24 commented Feb 17, 2022

@jtannas Apologies for the long delay, but here is a fix for the broken compatibility: #531

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 a pull request may close this issue.

4 participants