﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22089	Deleting object with custom primary_key causes the pk to be None	anonymous	nobody	"I am using PostgreSQL 9.3. I can reproduce this error every time. I have the following object model for my application:


{{{
class Location(models.Model):
    id = models.CharField(primary_key=True, max_length=20)
    ..  bunch of other non required fields ...

}}}

The location details view looks like this :


{{{
def location(request, location_id):
    # get the requested location
    location = Location.objects.get(pk=location_id)

    ... 

   elif request.POST.get('delete-button'):
        location.delete()
        messages.success(request, 'Location {0} was deleted.'.format(location_id))
        logger.info('User {0} has deleted location {1}.'.format(request.user, location_id))
        return redirect(reverse('locations_home'))
}}}


The redirect goes to a main locations page that runs a query set to get all locations

ls = Location.objects.all()

For each location a link is built using  {% url 'locaion_page' location.id %} 

The deleted object seems to be still pulled into the queryset as the delete operation didn't complete but the id field is now None or a blank character in the view. The application crashes with a NoReverse error for location_page with u'' 

Not sure why this started happening, it wasn't ever a problem, but now deletes seem to take longer and the amount of locations hasn't increased. ~ 100. 

When i did location.delete() in the shell and quickly ran location again, i noticed it was still there. I ran location.delete() again and I got an AssertionError which made sense.

I suspect this is a bug related to using a CharField primary key."	Uncategorized	closed	Database layer (models, ORM)	1.6	Normal	invalid		Roman Levin	Unreviewed	0	0	0	0	0	0
