I'm a bit at a loss as to where to go from here...

I have simple Link and Category models.  My Link model is essentially:
user_id, category (FK), name, URL.  I have a Meta unique_together on
(user, url) so no duplicate URLs get entered.  I'm testing this by
trying to purposefully enter a duplicate URL.

At first my code threw an IntegrityError so I'm trying to catch that.
Here's my create view:

def create(request):

    errors = {}

    if request.method == 'POST':
        form = LinkForm(request, request.POST)
        if form.is_valid():
            link = form.save(commit=False)
            link.user = request.user
            try:
                link.save()
            except IntegrityError:
                errors['Duplicate URL'] = 'That URL is already a
link.'
            else:
                return HttpResponseRedirect(reverse('links_index'))
    else:
        form = LinkForm(request)

    return render_to_response(
        'links/link_form.html', {
            'form': form,
            'errors': errors,
        },
        context_instance=RequestContext(request)
    )

But I get an InternalError.  Trackback below:

Environment:

Request Method: POST
Request URL: http://localhost:8000/links/create/
Django Version: 1.1 pre-alpha
Python Version: 2.5.4
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'private_apps.links',
 'django_extensions']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'private_apps.middleware.RequireLoginMiddleware')


Traceback:
File "/Users/rob/django/django-trunk/django/core/handlers/base.py" in
get_response
  86.                 response = callback(request, *callback_args,
**callback_kwargs)
File "/Users/rob/git/private_apps/private_apps/../private_apps/links/
views.py" in create
  61.         context_instance=RequestContext(request)
File "/Users/rob/django/django-trunk/django/template/context.py" in
__init__
  105.             self.update(processor(request))
File "/Users/rob/django/django-trunk/django/core/
context_processors.py" in auth
  27.         'messages': user.get_and_delete_messages(),
File "/Users/rob/django/django-trunk/django/contrib/auth/models.py" in
get_and_delete_messages
  262.         for m in self.message_set.all():
File "/Users/rob/django/django-trunk/django/db/models/query.py" in
_result_iter
  186.                 self._fill_cache()
File "/Users/rob/django/django-trunk/django/db/models/query.py" in
_fill_cache
  667.                     self._result_cache.append(self._iter.next
())
File "/Users/rob/django/django-trunk/django/db/models/query.py" in
iterator
  281.         for row in self.query.results_iter():
File "/Users/rob/django/django-trunk/django/db/models/sql/query.py" in
results_iter
  238.         for rows in self.execute_sql(MULTI):
File "/Users/rob/django/django-trunk/django/db/models/sql/query.py" in
execute_sql
  1935.         cursor.execute(sql, params)
File "/Users/rob/django/django-trunk/django/db/backends/util.py" in
execute
  19.             return self.cursor.execute(sql, params)

Exception Type: InternalError at /links/create/
Exception Value: current transaction is aborted, commands ignored
until end of transaction block


Since this looked like a transaction issue I tried adding a
transaction.rollback() to my IntegrityError except clause but that
threw its own error that it wasn't in transaction management.

Side note: I'm curious if the IntegrityError might be worth putting in
the metaclass to add to the base model class, so one doesn't need to
import it specifically, they could use `except Link.IntegrityError`?

Thanks,
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to