Log the failing SQL statement in vectorization task

Unique violations on packages_name_key happen on a statement that
cannot logically touch name - log the exact query and a longer
backtrace to identify what really fails.
This commit is contained in:
Christoph Haas 2026-08-23 00:31:04 +02:00
parent bada261841
commit 61b64fae25

View file

@ -30,6 +30,13 @@ namespace :debshots do
done = 0 done = 0
failed = 0 failed = 0
# Remember the most recent SQL statement so failures can be traced
# to the exact query that triggered them.
last_sql = nil
ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
last_sql = args.last[:sql]
end
scope.find_each do |package| scope.find_each do |package|
begin begin
raise ArgumentError, 'no description text' if package.embedding_text.blank? raise ArgumentError, 'no description text' if package.embedding_text.blank?
@ -41,7 +48,8 @@ namespace :debshots do
# enough detail to diagnose it and move on. # enough detail to diagnose it and move on.
failed += 1 failed += 1
logger.error "Failed for package #{package.name}: #{e.class}: #{e.message}" logger.error "Failed for package #{package.name}: #{e.class}: #{e.message}"
logger.error e.backtrace.first(3).join("\n") if e.backtrace logger.error "Last SQL: #{last_sql}"
logger.error e.backtrace.first(15).join("\n") if e.backtrace
end end
processed = done + failed processed = done + failed