sebbacon/alaveteli — Issue #395: Duplicate tracks detection is failing and falling back to DB constraints
Author: sebbacon
Created: 2012-01-30 09:09:10+00:00
State: open

There is at least one instance in the WDTK logs of a user trying to make a (user_updates) track, and getting an error from postgres because it already exists. There is code in the `TrackController` to catch duplicates but it appears to be failing in this case at least:

A ActiveRecord::StatementInvalid occurred in track#track_user:

PGError: ERROR: duplicate key value violates unique constraint "index_track_things_on_tracking_user_id_and_track_query"
: INSERT INTO "track_things" ("track_query", "track_medium", "created_at", "public_body_id", "updated_at", "info_request_id", "tracked_user_id", "track_type", "tracking_user_id") VALUES('requested_by:jennifer_odea OR commented_by:jennifer_odea', 'email_daily', '2012-01-29 13:36:05.537848', NULL, '2012-01-29 13:36:05.537848', NULL, 25015, 'user_updates', 27524) RETURNING "id"
[RAILS_ROOT]/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:227:in `log'

-------------------------------
:
-------------------------------

* URL : http://www.whatdotheyknow.com/track/user/jennifer_odea
* IP address: 86.2.84.235
* Parameters: {"action"=>"track_user", "url_name"=>"jennifer_odea", "controller"=>"track", "feed"=>"track"}
* Rails root: /data/vhost/www.whatdotheyknow.com/alaveteli

[RAILS_ROOT]/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:227:in `log'
[RAILS_ROOT]/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:520:in `execute'

[RAILS_ROOT]/vendor/rails/activerecord/lib/active_record/transactions.rb:200:in `save!'
[RAILS_ROOT]/app/controllers/track_controller.rb:116:in `track_set'
[RAILS_ROOT]/app/controllers/track_controller.rb:73:in `track_user'