Closed GoogleCodeExporter closed 9 years ago
Hm - in fact this seems to be occuring in a variety of places, not just the
delete method. Pretty much anything
that clears the cache. Perhaps wrapping the clear_cache method in a
try...except is the go here.
Original comment by dan.mack...@gmail.com
on 9 Oct 2008 at 2:16
This is pretty much how the Django ORM works with unsaved models. If a Photo
(or any other model) has
not been saved to the database there's no reason to call it's delete method,
nor is there a primary
key associated with the model for it to know WHAT to delete. If you try to do
this with say the User
model from django.contrib.auth.models you will get the following:
"AssertionError: User object can't be deleted because its id attribute is set
to None"
You're just not getting to that point because Photologue is assuming that the
model has been saved if
you're calling delete on it.
If you need to clear a model from memory that hasn't been saved you can just
del() it. The following
snippet handle the problem.
# do stuff
p = Picture()
# do more stuff and now we need to delete "p"
if p._get_pk_val() is None:
del(p)
else:
p.delete()
I have put a check in the ImageModel delete method (r349) that raises the same
assertion error for
consistency but I personally would still use the method above instead of
looking to catch the
AssertionError as I think it's more readable.
If you can be more specific on the "variety of places" that you're triggering
clear_cache on unsaved
models that would be helpful.
- Justin
Original comment by justin.d...@gmail.com
on 9 Oct 2008 at 1:23
I'm not convinced this is an issue so I'm going to mark it invalid. I'll reopen
the
ticket if you still feel this is an problem and can provide more details.
Original comment by justin.d...@gmail.com
on 17 Oct 2008 at 5:16
So, i've run into this problem, but through different means. I am trying to
delete a bunch of pictures (which just plainly subclass imagemodel):
class Picture(ImageModel):
pass
and when I use picture.delete(), all this does is clear the image attribute,
but the picture model remains! this is cluttering things up, and causing
errors when I create a new photosize or try to delete the picture from the
admin interface because it errors out as described by Dan.
I think this is worth investigating.
Original comment by quasiyo...@gmail.com
on 10 Aug 2010 at 9:43
Just ran into the same problem .. without using Photologue.
Like the original poster, I create a cache system using a model with an image
field which contains images fetched from the web with a management script.
At some point, I don't know how, deleting outdated cache stopped working. When
I ran the fetching script I always got that dreaded ValueError complaining that
there was no file associated with the field of my model.
Now the funny thing: I did a print on the file path, the file indeed did not
exists, but if I did a os.path.exists(path) and a os.path.isfile(path) they
always returned True.
Still scratching my head over this.
Original comment by hainea...@gmail.com
on 13 Jul 2011 at 3:58
Original issue reported on code.google.com by
dan.mack...@gmail.com
on 9 Oct 2008 at 1:42