Issue Details (XML | Word | Printable)

Key: FLM-299
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Borys Musielak
Reporter: Borys Musielak
Votes: 0
Watchers: 0
Operations

Clone this issue
Create sub-task
If you were logged in you would be able to see more operations.
Filmaster

Add a constraint check for Watching objects in database

Created: 25/Feb/10 01:55 PM   Updated: 14/Mar/10 05:03 PM
Component/s: None
Affects Version/s: 1.0.3
Fix Version/s: 1.0.3

Time Tracking:
Not Specified


 Description  « Hide
Traceback (most recent call last):

  File "/home/filmaster/django-trunk-hacked/django/core/handlers/base.py", =
line 87, in get_response
    response =3D middleware_method(request, callback, callback_args, callba=
ck_kwargs)

  File "/home/filmaster/film20/film20/core/middleware.py", line 170, in pro=
cess_view
    return show_blog_post(request, permalink, subdomain)

  File "/home/filmaster/film20/film20/blog/views.py", line 172, in show_blo=
g_post
    subscribe_action =3D watching_helper.get_subscribe_action(request.user,=
 post)

  File "/home/filmaster/filmaster-stable/film20/../film20/useractivity/watc=
hing_helper.py", line 140, in get_subscribe_action
    watching =3D Watching.objects.get(object=3Dobject, user=3Duser)

  File "/home/filmaster/django-trunk-hacked/django/db/models/manager.py", l=
ine 120, in get
    return self.get_query_set().get(*args, **kwargs)

  File "/home/filmaster/django-trunk-hacked/django/db/models/query.py", lin=
e 307, in get
    % (self.model._meta.object_name, num, kwargs))

MultipleObjectsReturned: get() returned more than one Watching -- it return=
ed 3! Lookup parameters were {'object': <Post: Galerianki na golasa>, 'user=
': <User: michuk>}


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Borys Musielak added a comment - 14/Mar/10 04:55 PM
ALTER TABLE "useractivity_watching" ADD CONSTRAINT "one_watching_per_object" UNIQUE ("object_id" , "user_id");

Borys Musielak added a comment - 14/Mar/10 05:01 PM
applied on dev and prod.

Borys Musielak added a comment - 14/Mar/10 05:03 PM
Additionally, added a not-null constraint for object_id (for some reason there were watching objects watching nothing):

DELETE FROM useractivity_watching where object_id is null;
ALTER TABLE "useractivity_watching" ALTER object_id SET NOT NULL;