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

ActiveModel::UnknownAttributeError with upsert #1099

Open
dewey opened this issue Feb 21, 2023 · 0 comments
Open

ActiveModel::UnknownAttributeError with upsert #1099

dewey opened this issue Feb 21, 2023 · 0 comments

Comments

@dewey
Copy link

dewey commented Feb 21, 2023

Hey—

I'm using this library and I'm running into a problem where I'm not sure if it's something I'm doing wrong or a bug when using it with upsert_all. I'm using the following version in a Rails 7.0.4.2 project with Ruby 3.0.3.

Setup

    acts-as-taggable-on (9.0.1)
      activerecord (>= 6.0, < 7.1)

My model: Bookmark

  acts_as_ordered_taggable
  acts_as_taggable_on :tags

  def public?
    self.tag_list.include?('some-tag')
  end

Stacktrace

ActiveModel::UnknownAttributeError (unknown attribute 'tag_list' for Bookmark.):
19:45:33 web.1    | /Users/philipp/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/activerecord-7.0.4.2/lib/active_record/insert_all.rb:264:in `extract_types_from_columns_on'
19:45:33 web.1    | /Users/philipp/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/activerecord-7.0.4.2/lib/active_record/insert_all.rb:199:in `values_list'
19:45:33 web.1    | /Users/philipp/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/activerecord-7.0.4.2/lib/active_record/connection_adapters/postgresql_adapter.rb:515:in `build_insert_sql'
19:45:33 web.1    | /Users/philipp/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/activerecord-7.0.4.2/lib/active_record/insert_all.rb:153:in `to_sql'
19:45:33 web.1    | /Users/philipp/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/activerecord-7.0.4.2/lib/active_record/insert_all.rb:41:in `execute'
19:45:33 web.1    | /Users/philipp/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/activerecord-7.0.4.2/lib/active_record/persistence.rb:333:in `upsert_all'

The line inserted_bookmarks is the one causing the issues in this case.

                bookmarks = []
                tweet_upserted.each do |existing_tweet|
                  @bookmark = Bookmark.new
                  @bookmark.user = @user
                  @bookmark.tweet_id = existing_tweet['id'].to_i
                  @bookmark.source = 'FetchTwitterUserBookmarksJob'
                  bookmarks << @bookmark.as_json(except: %i[id created_at updated_at sent_at materialized_at note])
                end

                inserted_bookmarks = Bookmark.upsert_all(bookmarks,
                                                         unique_by: %i[user_id tweet_id],
                                                         returning: %i[id]
                )

Are you aware of anything in this library that would cause issues when used like that?

Thank you!

Update

I found that by adding tag_list to the except list of @bookmark.as_json I can prevent this error, I'm leaving this open as I'm not sure if that's something that should be done on the library level or that I'm just using it wrong.

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

No branches or pull requests

1 participant