You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "Jason Smith (JIRA)" <ji...@apache.org> on 2010/06/16 09:36:23 UTC

[jira] Created: (COUCHDB-802) Doc ID should auto-generate if not provided, before sending to _update function [PATCH]

Doc ID should auto-generate if not provided, before sending to _update function [PATCH]
---------------------------------------------------------------------------------------

                 Key: COUCHDB-802
                 URL: https://issues.apache.org/jira/browse/COUCHDB-802
             Project: CouchDB
          Issue Type: Bug
          Components: HTTP Interface, JavaScript View Server
    Affects Versions: 0.11
         Environment: Linux
            Reporter: Jason Smith
            Priority: Minor
             Fix For: 0.11.1


The main bug is this: _show and _update functions should be able to mimic the standard HTTP/JSON API. A common pattern people are moving to is rewriting to _show and _update, so the client thinks it is hitting normal couch, however additional logic happens (e.g. auto-timestamping).

Unfortunately, _update cannot return an auto-generated ID for POST to /db/_design/ddoc/_update. The semantics should match POST to /db/ -- If an _id is provided, use that; otherwise auto-generate one. The best an _update function can do now is Math.random() or similar; however one loses the advantage of sequential UUID generation from couch's internals.

The fix is for couch to send a random UUID if the update URL did not include the final /Id component. The function itself in the view server can decide whether to use it. Assuming that change, the update function could at least be capable of duplicating the direct API using the following Javascript logic:

  function(doc, req) {
    if(doc && doc._id == req.id) {
      // To be pedantic, I could confirm req.method == "PUT"
      log("I am an update by id");
    } else if(doc === null && req.id) {
      if(req.method == "POST") {
        log("I am a create, id was auto-generated");
      } else if(req.method == "PUT") {
        log("I am a create, id was supplied by client");
      }
    }
  }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (COUCHDB-802) Doc ID should auto-generate if not provided, before sending to _update function [PATCH]

Posted by "Zachary Zolton (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COUCHDB-802?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Zachary Zolton updated COUCHDB-802:
-----------------------------------

    Attachment: COUCHDB-802-with-test.diff

Will this test suffice? (^_^)


> Doc ID should auto-generate if not provided, before sending to _update function [PATCH]
> ---------------------------------------------------------------------------------------
>
>                 Key: COUCHDB-802
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-802
>             Project: CouchDB
>          Issue Type: Bug
>          Components: HTTP Interface, JavaScript View Server
>    Affects Versions: 0.11
>         Environment: Linux
>            Reporter: Jason Smith
>            Priority: Minor
>             Fix For: 0.11.1
>
>         Attachments: COUCHDB-802-with-test.diff, new_id.diff
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> The main bug is this: _show and _update functions should be able to mimic the standard HTTP/JSON API. A common pattern people are moving to is rewriting to _show and _update, so the client thinks it is hitting normal couch, however additional logic happens (e.g. auto-timestamping).
> Unfortunately, _update cannot return an auto-generated ID for POST to /db/_design/ddoc/_update. The semantics should match POST to /db/ -- If an _id is provided, use that; otherwise auto-generate one. The best an _update function can do now is Math.random() or similar; however one loses the advantage of sequential UUID generation from couch's internals.
> The fix is for couch to send a random UUID if the update URL did not include the final /Id component. The function itself in the view server can decide whether to use it. Assuming that change, the update function could at least be capable of duplicating the direct API using the following Javascript logic:
>   function(doc, req) {
>     if(doc && doc._id == req.id) {
>       // To be pedantic, I could confirm req.method == "PUT"
>       log("I am an update by id");
>     } else if(doc === null && req.id) {
>       if(req.method == "POST") {
>         log("I am a create, id was auto-generated");
>       } else if(req.method == "PUT") {
>         log("I am a create, id was supplied by client");
>       }
>     }
>   }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (COUCHDB-802) Doc ID should auto-generate if not provided, before sending to _update function [PATCH]

Posted by "Chris Anderson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COUCHDB-802?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Chris Anderson closed COUCHDB-802.
----------------------------------

    Resolution: Fixed

applied in r955389

Thanks everyone. I changed the patch slightly on the way in, so it adds a req.uuid to every request. This way the "hello" test isn't busted.

> Doc ID should auto-generate if not provided, before sending to _update function [PATCH]
> ---------------------------------------------------------------------------------------
>
>                 Key: COUCHDB-802
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-802
>             Project: CouchDB
>          Issue Type: Bug
>          Components: HTTP Interface, JavaScript View Server
>    Affects Versions: 0.11
>         Environment: Linux
>            Reporter: Jason Smith
>            Priority: Minor
>             Fix For: 0.11.1
>
>         Attachments: COUCHDB-802-with-test.diff, COUCHDB-802-with-test_take2.diff, COUCHDB-802-with-test_take3.diff, new_id.diff
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> The main bug is this: _show and _update functions should be able to mimic the standard HTTP/JSON API. A common pattern people are moving to is rewriting to _show and _update, so the client thinks it is hitting normal couch, however additional logic happens (e.g. auto-timestamping).
> Unfortunately, _update cannot return an auto-generated ID for POST to /db/_design/ddoc/_update. The semantics should match POST to /db/ -- If an _id is provided, use that; otherwise auto-generate one. The best an _update function can do now is Math.random() or similar; however one loses the advantage of sequential UUID generation from couch's internals.
> The fix is for couch to send a random UUID if the update URL did not include the final /Id component. The function itself in the view server can decide whether to use it. Assuming that change, the update function could at least be capable of duplicating the direct API using the following Javascript logic:
>   function(doc, req) {
>     if(doc && doc._id == req.id) {
>       // To be pedantic, I could confirm req.method == "PUT"
>       log("I am an update by id");
>     } else if(doc === null && req.id) {
>       if(req.method == "POST") {
>         log("I am a create, id was auto-generated");
>       } else if(req.method == "PUT") {
>         log("I am a create, id was supplied by client");
>       }
>     }
>   }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (COUCHDB-802) Doc ID should auto-generate if not provided, before sending to _update function [PATCH]

Posted by "Chris Anderson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COUCHDB-802?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12879367#action_12879367 ] 

Chris Anderson commented on COUCHDB-802:
----------------------------------------

If anyone can add a test case I'll commit it. I can't promise I've got time to add the test case myself. Should be a small JS test patch.

> Doc ID should auto-generate if not provided, before sending to _update function [PATCH]
> ---------------------------------------------------------------------------------------
>
>                 Key: COUCHDB-802
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-802
>             Project: CouchDB
>          Issue Type: Bug
>          Components: HTTP Interface, JavaScript View Server
>    Affects Versions: 0.11
>         Environment: Linux
>            Reporter: Jason Smith
>            Priority: Minor
>             Fix For: 0.11.1
>
>         Attachments: new_id.diff
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> The main bug is this: _show and _update functions should be able to mimic the standard HTTP/JSON API. A common pattern people are moving to is rewriting to _show and _update, so the client thinks it is hitting normal couch, however additional logic happens (e.g. auto-timestamping).
> Unfortunately, _update cannot return an auto-generated ID for POST to /db/_design/ddoc/_update. The semantics should match POST to /db/ -- If an _id is provided, use that; otherwise auto-generate one. The best an _update function can do now is Math.random() or similar; however one loses the advantage of sequential UUID generation from couch's internals.
> The fix is for couch to send a random UUID if the update URL did not include the final /Id component. The function itself in the view server can decide whether to use it. Assuming that change, the update function could at least be capable of duplicating the direct API using the following Javascript logic:
>   function(doc, req) {
>     if(doc && doc._id == req.id) {
>       // To be pedantic, I could confirm req.method == "PUT"
>       log("I am an update by id");
>     } else if(doc === null && req.id) {
>       if(req.method == "POST") {
>         log("I am a create, id was auto-generated");
>       } else if(req.method == "PUT") {
>         log("I am a create, id was supplied by client");
>       }
>     }
>   }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (COUCHDB-802) Doc ID should auto-generate if not provided, before sending to _update function [PATCH]

Posted by "Dmitry Unkovsky (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COUCHDB-802?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dmitry Unkovsky updated COUCHDB-802:
------------------------------------

    Attachment: COUCHDB-802-with-test_take2.diff
                COUCHDB-802-with-test_take3.diff

It seemed to break previous tests. Should not to POST against "hello" update handler (that's take2) or slightly modify update tests against "hello" handler (take3).

> Doc ID should auto-generate if not provided, before sending to _update function [PATCH]
> ---------------------------------------------------------------------------------------
>
>                 Key: COUCHDB-802
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-802
>             Project: CouchDB
>          Issue Type: Bug
>          Components: HTTP Interface, JavaScript View Server
>    Affects Versions: 0.11
>         Environment: Linux
>            Reporter: Jason Smith
>            Priority: Minor
>             Fix For: 0.11.1
>
>         Attachments: COUCHDB-802-with-test.diff, COUCHDB-802-with-test_take2.diff, COUCHDB-802-with-test_take3.diff, new_id.diff
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> The main bug is this: _show and _update functions should be able to mimic the standard HTTP/JSON API. A common pattern people are moving to is rewriting to _show and _update, so the client thinks it is hitting normal couch, however additional logic happens (e.g. auto-timestamping).
> Unfortunately, _update cannot return an auto-generated ID for POST to /db/_design/ddoc/_update. The semantics should match POST to /db/ -- If an _id is provided, use that; otherwise auto-generate one. The best an _update function can do now is Math.random() or similar; however one loses the advantage of sequential UUID generation from couch's internals.
> The fix is for couch to send a random UUID if the update URL did not include the final /Id component. The function itself in the view server can decide whether to use it. Assuming that change, the update function could at least be capable of duplicating the direct API using the following Javascript logic:
>   function(doc, req) {
>     if(doc && doc._id == req.id) {
>       // To be pedantic, I could confirm req.method == "PUT"
>       log("I am an update by id");
>     } else if(doc === null && req.id) {
>       if(req.method == "POST") {
>         log("I am a create, id was auto-generated");
>       } else if(req.method == "PUT") {
>         log("I am a create, id was supplied by client");
>       }
>     }
>   }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (COUCHDB-802) Doc ID should auto-generate if not provided, before sending to _update function [PATCH]

Posted by "Jason Smith (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COUCHDB-802?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jason Smith updated COUCHDB-802:
--------------------------------

    Attachment: new_id.diff

One-line change so the logic in the OP would work. Unfortunately I haven't had the time to make the test case. I will attach that in a subsequent message.

> Doc ID should auto-generate if not provided, before sending to _update function [PATCH]
> ---------------------------------------------------------------------------------------
>
>                 Key: COUCHDB-802
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-802
>             Project: CouchDB
>          Issue Type: Bug
>          Components: HTTP Interface, JavaScript View Server
>    Affects Versions: 0.11
>         Environment: Linux
>            Reporter: Jason Smith
>            Priority: Minor
>             Fix For: 0.11.1
>
>         Attachments: new_id.diff
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> The main bug is this: _show and _update functions should be able to mimic the standard HTTP/JSON API. A common pattern people are moving to is rewriting to _show and _update, so the client thinks it is hitting normal couch, however additional logic happens (e.g. auto-timestamping).
> Unfortunately, _update cannot return an auto-generated ID for POST to /db/_design/ddoc/_update. The semantics should match POST to /db/ -- If an _id is provided, use that; otherwise auto-generate one. The best an _update function can do now is Math.random() or similar; however one loses the advantage of sequential UUID generation from couch's internals.
> The fix is for couch to send a random UUID if the update URL did not include the final /Id component. The function itself in the view server can decide whether to use it. Assuming that change, the update function could at least be capable of duplicating the direct API using the following Javascript logic:
>   function(doc, req) {
>     if(doc && doc._id == req.id) {
>       // To be pedantic, I could confirm req.method == "PUT"
>       log("I am an update by id");
>     } else if(doc === null && req.id) {
>       if(req.method == "POST") {
>         log("I am a create, id was auto-generated");
>       } else if(req.method == "PUT") {
>         log("I am a create, id was supplied by client");
>       }
>     }
>   }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.