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

Avoid UnknownAttributeReference error by eliminating Array#join #226

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marksiemers
Copy link

No description provided.

@marksiemers
Copy link
Author

I've continued testing this, and it does not yet fix all cases.

This works when processing one record at a time, but when attempting in_batches the same error shows up in a different part of the code (calling pluck)

I believe it is this code:

    def pluck_columns(relation)
      if @pluck_columns.size == 1 # only the primary key
        column_values = relation.pluck(*@pluck_columns)
        return [column_values, column_values]
      end

      column_values = relation.pluck(*@pluck_columns)
      primary_key_index = @primary_key_index || -1
      primary_key_values = column_values.map { |values| values[primary_key_index] }

      serialize_column_values!(column_values)
      [column_values, primary_key_values]
    end

And using Arel.sql did not fix it, so something more in depth may be required.

@etiennebarrie
Copy link
Member

Can you share a bit more about the relation you're passing to job-iteration (in collection)?

@marksiemers
Copy link
Author

marksiemers commented Jun 3, 2022

Sure thing, what is working using the code in this PR, but was not without this change is the following:

UPDATE:

For clarification, OrdinanceLookup and OrdinanceLookupBatch are ActiveRecord models, and ordinance_lookups is a has_many association on the OrdinanceLookupBatch model.

ORIGINAL

  def collection
    return OrdinanceLookup.none unless status.in?(DataSetJobStatus::VALID_STATUSES)

    batch = OrdinanceLookupBatch.find_by!(external_identifier: batch_external_identifier)
    batch.ordinance_lookups
  end

What still isn't working is:

  def collection
    return OrdinanceLookup.none unless status.in?(DataSetJobStatus::VALID_STATUSES)

    batch = OrdinanceLookupBatch.find_by!(external_identifier: batch_external_identifier)
    batch.ordinance_lookups.in_batches
  end

Perhaps it is that the collection is an association?

Do you think it would work to have:

batch = OrdinanceLookupBatch.find_by!(external_identifier: batch_external_identifier)
OrdinanceLookup.where(batch: batch)

@bray
Copy link

bray commented Oct 5, 2023

We're still seeing this. Any update on a fix?

@Mangara
Copy link
Contributor

Mangara commented Oct 5, 2023

It's not entirely clear to me what this fixes. The code in #226 (comment) seems to be for a maintenance task, not a direct job-iteration job. Could you add a test that fails without this change and passes with it?

@marksiemers
Copy link
Author

I have signed the CLA

@marksiemers marksiemers force-pushed the fix-unknown-attribute-reference-error branch from 3323ec8 to dd82aca Compare May 21, 2024 19:41
@marksiemers marksiemers force-pushed the fix-unknown-attribute-reference-error branch from dd82aca to fba2b54 Compare May 21, 2024 20:08
@marksiemers marksiemers changed the title Use Arel.sql to avoid UnknownAttributeReference Avoid UnknownAttributeReference error by eliminating Array#join May 22, 2024
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