Skip to content

fix ActiveRecord::RecordNotFound: [WHERE "content_objects"."uri" = $1] - #175

Open
arte7 wants to merge 1 commit into
mainfrom
record_404
Open

fix ActiveRecord::RecordNotFound: [WHERE "content_objects"."uri" = $1]#175
arte7 wants to merge 1 commit into
mainfrom
record_404

Conversation

@arte7

@arte7 arte7 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

https://discovery.joinmastodon.org/jobs/applications/fediscoverer/jobs/222622af-54a2-409a-92c3-ade606aa1367?server_id=solid_queue

ActiveRecord::RecordNotFound: Couldn't find ContentObject with [WHERE "content_objects"."uri" = $1]

in ContentObject::create_from_json! it is possible, that the RetrieveActorJob runs and has to create a new actor, while the next step in create_from_json! is to retrieve the actor from the database, which might not be there yet.

are we fine with catching this error, or do we want a retry?

/usr/local/bundle/ruby/4.0.0/gems/activerecord-8.1.3.1/lib/active_record/relation/finder_methods.rb:425:in 'ActiveRecord::FinderMethods#raise_record_not_found_exception!'
/usr/local/bundle/ruby/4.0.0/gems/activerecord-8.1.3.1/lib/active_record/relation/finder_methods.rb:135:in 'ActiveRecord::FinderMethods#take!'
/usr/local/bundle/ruby/4.0.0/gems/activerecord-8.1.3.1/lib/active_record/relation/finder_methods.rb:118:in 'ActiveRecord::FinderMethods#find_by!'
/usr/local/bundle/ruby/4.0.0/gems/activerecord-8.1.3.1/lib/active_record/relation.rb:305:in 'block in ActiveRecord::Relation#create_or_find_by!'
/usr/local/bundle/ruby/4.0.0/gems/activerecord-8.1.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:463:in 'ActiveRecord::ConnectionAdapters::ConnectionPool#with_connection'
/usr/local/bundle/ruby/4.0.0/gems/activerecord-8.1.3.1/lib/active_record/connection_handling.rb:313:in 'ActiveRecord::ConnectionHandling#with_connection'
/usr/local/bundle/ruby/4.0.0/gems/activerecord-8.1.3.1/lib/active_record/relation/delegation.rb:105:in 'ActiveRecord::Delegation#with_connection'
/usr/local/bundle/ruby/4.0.0/gems/activerecord-8.1.3.1/lib/active_record/relation.rb:294:in 'ActiveRecord::Relation#create_or_find_by!'
/usr/local/bundle/ruby/4.0.0/gems/activerecord-8.1.3.1/lib/active_record/relation.rb:239:in 'ActiveRecord::Relation#find_or_create_by!'
/rails/app/models/content_object.rb:81:in 'ContentObject.create_from_json!'
/rails/app/jobs/retrieve_content_job.rb:30:in 'RetrieveContentJob#perform'

implements WEB-1205

@oneiros

oneiros commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

in ContentObject::create_from_json! it is possible, that the RetrieveActorJob runs and has to create a new actor, while the next step in create_from_json! is to retrieve the actor from the database, which might not be there yet.

That should not be possible. Please note that the job is being performed by a call to perform_now. This should not only perform the job immediately, it also runs it inline, blocking until it finishes.

But it is true that it might not be able to create the missing actor.

That is why

actor = Actor.where(uri: actor_uri).take

is chosen this way (as opposed to e.g. using .find_by), because it should never raise ActiveRecord::RecordNotFound, but will just return nil if there is no matching record.

return unless actor&.content_indexable?

then takes of that case and returns early if actor is nil.

Last but not least, the error you linked to is raised in this line:

create_with(attributes).find_or_create_by!(uri: json_object["id"])

and is not about the actor URI, but the URI of the content object itself.

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