From user-return-11117-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Wed Jun 23 17:40:31 2010 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 19093 invoked from network); 23 Jun 2010 17:40:31 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 23 Jun 2010 17:40:31 -0000 Received: (qmail 75024 invoked by uid 500); 23 Jun 2010 17:40:30 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 74977 invoked by uid 500); 23 Jun 2010 17:40:29 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 74969 invoked by uid 99); 23 Jun 2010 17:40:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Jun 2010 17:40:29 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of redhatdude@gmail.com designates 74.125.83.52 as permitted sender) Received: from [74.125.83.52] (HELO mail-gw0-f52.google.com) (74.125.83.52) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Jun 2010 17:40:21 +0000 Received: by gwb17 with SMTP id 17so1472598gwb.11 for ; Wed, 23 Jun 2010 10:39:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=JUVU/aorXqXAIwaittNgu4YTplu6O0JXmo9v7p8wLQs=; b=bRJam33WOwmU2ypXiJmy5tC9Lei5WreUZg0xpCD/kXxW2GbCDG/WmicMJHIIgk9CsP S8+hFFNFpUVfiREY5fvyouUeB/BWpC1WQUTd4Ye9YqGc/LaxrYuhzG2DKcafXsBcLccI bHIY0qBIIyuDZsV6fKoAjkNSOJQEAMZ3zDYyg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; b=DTvL6pg1oZV/7d+pF1IxYGMGuSsKNXyNWu5mKpJKvg3fdqrM7JgEXwCNlu/0rChNag flQ7nWTB2UgrtMQFQRO7fdwehM9izXr2Eears0LYMzQ2chhYC8FVx1Fse7KLR/vYaGam X6+5HqQO3+114VhDINGUqMqU4QixL+wAZynLw= MIME-Version: 1.0 Received: by 10.90.24.7 with SMTP id 7mr5140731agx.204.1277314799729; Wed, 23 Jun 2010 10:39:59 -0700 (PDT) Sender: redhatdude@gmail.com Received: by 10.90.95.9 with HTTP; Wed, 23 Jun 2010 10:39:59 -0700 (PDT) In-Reply-To: <7F4EEA33-2F69-447F-8B7C-EDCEB8EA643E@apache.org> References: <7F4EEA33-2F69-447F-8B7C-EDCEB8EA643E@apache.org> Date: Wed, 23 Jun 2010 13:39:59 -0400 X-Google-Sender-Auth: EP22GTN6l3CdelVtQctkA47gu7s Message-ID: Subject: Re: A question about attachments, stubs, and revpos From: Caleb Land To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=001636164427e77c230489b606c2 X-Virus-Checked: Checked by ClamAV on apache.org --001636164427e77c230489b606c2 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jun 23, 2010 at 1:29 PM, Damien Katz wrote: > > On Jun 23, 2010, at 10:24 AM, Caleb Land wrote: > > > I'm writing a CouchDB library for ruby (who isn't these days :)), partly > for > > my own use, and partly to teach myself about how couch works, and play > with > > some ideas I have about working with it. > > > > I've begun to implement attachments, and I'm a bit stuck about how to go > > forward. > > > > Basically, I want to know how I can: > > > > 1) GET a document and store it in an object > > 2) PUT an attachment to that document > > 3) PUT that document with revised fields > > > > The problem is, when I PUT the attachment, the document is updated and > the > > new document rev is returned. I can easily stuff this rev into the _rev > > field of my local document (like everyone does when they PUT a > document... > > so subsequent PUTs use the correct _rev), but the problem comes when I > need > > to PUT the document, and that document doesn't have the stub for the > newly > > uploaded attachment. > > > > I asked this question on IRC and got a reasonable answer back: Don't > modify > > a document twice in a row without fetching it in between. > > > > This makes sense, but then I thought about how when we save documents, we > > update our local copy's _rev with the rev returned by the server so we > > wouldn't have to fetch it again. > > > > Also, if the local document has some other fields that have changed > (let's > > say so that we could do validation before uploading the attachments), > then > > we have problems. > > > > I can see two options to handle this: > > > > 1) fetch the document again and grab the _attachments and find the new > > attachment and merge it in with the local document > > > > 2) build a stub and inject it into the local document: > > { > > 'stub': true, > > 'revpos': parseInt(return_from_attachment_put['rev']) // * > > } > > I'd use the second option, though I'm pretty sure you don't need the revpos > for a stub, so just leave that out and it should be fine. > > That's what I thought too, but if I don't include the revpos, I get an precondition failed status, with the error: {"error":"missing_stub","reason":"id:test, name:graph.html"} should I raise an issue in JIRA? > -Damien > > > > > * I'm not sure about this, since I didn't see a formal definition for > > 'revpos' anywhere, but this seems to be how it works > > > > My question is, what would an experienced CouchDB developer do in this > > situation? > > > > > > -- > > Caleb Land > > -- Caleb Land --001636164427e77c230489b606c2--