List Info

Thread: Saving FileFields is not atomar




Saving FileFields is not atomar
country flaguser name
United States
2007-02-28 08:37:30
Hi,
I ran into two problems.
First: How to save Files in a custom directory based on the
filecontent?
Second: How to let the Database ensure that all Filenames
are unique?

I've solved the first one by overriding the
'_save_FIELD_file' -
Method of my Model, which is not nice since I do some
djang-code
copying, but works.
I've also added a UNIQUE-Index to my 'file'-column.

What happens if the DB recognized that a filename already
exists?
Django first creates a db entry with a blank value for
'file' and than
trys to fill it with the filename. The last action fails and
so I've
got a new DB-Entry with no content.
This wouldn't even be too bad if I could still add more
files. This is
not possible because django trys to create another entry
with that
blank field and that fails because of  the UNIQUE-Index.

It seems to me that the problem is that filecreation and
filenameupdate is not atomar, not in one transaction.
Is that a Bug or a somewhat speed realated 'feature'?
Do you have a Hint for me how I could solve my problems more
niftily?

mfg
- stanz

initially:
id | file
-----------------
00| 'myfilename'

insert same file:
00|'myfilename'
01|'' #Blank entry remains and no more files can be added


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Saving FileFields is not atomar
country flaguser name
United States
2007-02-28 09:43:02
Okay I guess TransactionMiddleware should solve it.

I've got another question:
How can I create db entrys with ImageFields inside by myself
without
any forms? Say I've got image1 and want to create another
entry with
image1 in smaller size.

- stanz


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )