d devhelper

← All errors

Code bug

ActiveRecord::StatementInvalid

PG::UndefinedTable: ERROR: missing FROM-clause entry for table "member_content_view_summaries" LINE 1: ...ents" WHERE "contents"."is_independent" = $1 AND (member_con... ^

MemberContentsRefreshJob@contents_refresh163 events · 0 users first seen 7 d agolast seen 1 h ago

In one line

Members with no programs, tags or care managers get a Content query that never joins member_content_view_summaries, but refresh_member_contents filters and sorts on that table, so Postgres raises.

Checked against the code

What happened

  • Content.filter only joins member_content_view_summaries when a program, tag or care-manager filter exists.
  • For members with none of those, it returns a plain `Content.select('contents.*').independent` with no join.
  • Member#refresh_member_contents then adds `.where('member_content_view_summaries.completed ...')` and a reorder on that table, giving 'missing FROM-clause entry'.
  • 425 events over 7 days fits a recurring job hitting the same members repeatedly. It is not a deploy blip.

What to do next

  1. Code fix In app/models/content.rb, Content.filter: change the final else branch (line ~173) so that when member is present it selects the same summary columns and adds the same LEFT OUTER JOIN on member_content_view_summaries for member.id, plus the same reorder as the first branch. Keep `Content.select('contents.*').independent` when member is nil.
  2. Query Lists members with no programs, who are the likely failing ones. This assumes the table is named member_programs, so check db/schema.rb first.
    SELECT m.id FROM members m WHERE NOT EXISTS (SELECT 1 FROM member_programs mp WHERE mp.member_id = m.id) LIMIT 20;

Queries are shown, never run. Check them before using them on production.

Ask a follow-up

Continues the same session, so it still remembers the error and the code it read.

Enter to send · Shift+Enter for a new line
Analysed 1 h ago · claude-sonnet-5-5 · $0.05