lanto03 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

database.delete(doc) can delete itself #123

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. get database object
2. run DATABASE.delete({"_id": None, "_rev":None})
3.

What is the expected output? What do you see instead?
expected output: nothing happens or exception trown
what happens : database gets request: 'DELETE' /database 200
and deletes whole database

What version of the product are you using? On what operating system?
MacOs/ ubuntu
0.6

Please provide any additional information below.
quick patch:
--- a/couchdb/client.py
+++ b/couchdb/client.py
@@ -439,7 +439,8 @@ class Database(object):
         :raise ResourceConflict: if the document was updated in the database
         :since: 0.4.1
         """
-        self.resource.delete(doc['_id'], rev=doc['_rev'])
+        if doc.get('_id'):
+            self.resource.delete(doc['_id'], rev=doc['_rev'])

     def get(self, id, default=None, **options):
         """Return the document with the specified ID.

Original issue reported on code.google.com by Engr...@gmail.com on 8 Apr 2010 at 11:55

GoogleCodeExporter commented 8 years ago
It's really programmer error to call delete with {'_id': None, '_rev': None} 
but 
there's no way we should be deleting the database because of it!

However, for whoever gets to fix this, I think the real issue is that the 
http.urljoin 
function is masking errors like this by skipping None path segments, 
http://code.google.com/p/couchdb-python/source/browse/couchdb/http.py#470. 
Remove the 
if filter from the list comp and fix calls to urljoin and the application 
should get 
an exception, allowing the developer to debug.

Original comment by matt.goo...@gmail.com on 9 Apr 2010 at 11:01

GoogleCodeExporter commented 8 years ago
Matt, I don't think the change you're proposing is possible, unless we pick some
other sentinel (than None) in some of our URL functions. Which I'm not sure is 
better.

That said, I did implement r3001f35342ed, which goes in the direction you 
proposed. I
ended up fixing up the actual issue with the cruder r25d42ec60d79.

Original comment by djc.ochtman on 10 Apr 2010 at 4:07

GoogleCodeExporter commented 8 years ago
That fix is good enough.

One other thing if you try to load document with '_id' = None you will get db 
info. Instead of exception.

Original comment by Engr...@gmail.com on 12 Apr 2010 at 6:59