Updating wierdness - updating a deleted task creates a new task

0 views
Skip to first unread message

wka

unread,
Jan 13, 2009, 10:20:02 PM1/13/09
to Hiveminder API Hackers
(Given all of the spam in this group lately, I don't know if anyone is
reading, but if anyone is...)

I am working on a little app which uses the Hiveminder API. The app
will download tasks and let users modify them offline, syncing changes
back to Hiveminder. I presume that situations may occur where a task
is deleted on Hiveminder.com but still exists in the app. This is
where I am encountering an issue: when I try to do an update of a task
which has already been deleted.

I would expect some sort of error when updating the deleted task, just
like the 404 returned when trying to read it. Instead, the update
creates a new task.

If this is intended behavior, are there any recommendations on how to
tell if a task has been deleted as part of an update operation
(without the side-effect of creating a new task)? I would prefer not
to issue a read request before every update to check for a 404 error.
The app may be running in low-bandwidth situations, and multiple HTTP
requests add up.

Here is an example using curl:

# Create a new task
curl -i -b JIFTY_SID_HIVEMINDER=<COOKIE> -d summary=test1
http://hiveminder.com/=/model/Task.xml

HTTP/1.1 302 Found
Date: Wed, 14 Jan 2009 02:55:59 GMT
Server: Apache
Location: http://hiveminder.com/=/model/BTDT%3A%3AModel%3A%3ATask/id/584435
Transfer-Encoding: chunked
Content-Type: text/xml; charset=UTF-8

<data>
<action_class>BTDT::Action::CreateTask</action_class>
<content>
<id>584435</id>
</content>
<error></error>
<failure>0</failure>
<field_errors></field_errors>
<field_warnings></field_warnings>
<message>Your task has been created!</message>
<success>1</success>
</data>


# Delete it
curl -i -b JIFTY_SID_HIVEMINDER=<COOKIE> http://hiveminder.com/=/model/Task/id/584435.xml

curl -i -X DELETE -b JIFTY_SID_HIVEMINDER=<COOKIE>
http://hiveminder.com/=/model/Task/id/584435.xml
HTTP/1.1 302 Found
Date: Wed, 14 Jan 2009 02:58:13 GMT
Server: Apache
Location: http://hiveminder.com/=/model/BTDT%3A%3AModel%3A%3ATask/id/584435
Transfer-Encoding: chunked
Content-Type: text/xml; charset=UTF-8

<data>
<action_class>BTDT::Action::DeleteTask</action_class>
<content></content>
<error></error>
<failure>0</failure>
<field_errors></field_errors>
<field_warnings></field_warnings>
<message>Deleted task</message>
<success>1</success>
</data>

# Attempt to read it
curl -i -b JIFTY_SID_HIVEMINDER=<COOKIE> http://hiveminder.com/=/model/Task/id/584435.xml
HTTP/1.1 404
Date: Wed, 14 Jan 2009 02:58:44 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: text/html; charset=ISO-8859-1

404 Not Found

# Attempt to update it

curl -X PUT -d summary=test2 -b JIFTY_SID_HIVEMINDER=<COOKIE>
http://hiveminder.com/=/model/Task/id/584435.xml

HTTP/1.1 302 Found
Date: Wed, 14 Jan 2009 03:01:33 GMT
Server: Apache
Location: http://hiveminder.com/=/model/BTDT%3A%3AModel%3A%3ATask/id/584438
Transfer-Encoding: chunked
Content-Type: text/xml; charset=UTF-8

<data>
<action_class>BTDT::Action::CreateTask</action_class>
<content>
<id>584438</id>
</content>
<error></error>
<failure>0</failure>
<field_errors></field_errors>
<field_warnings></field_warnings>
<message>Your task has been created!</message>
<success>1</success>
</data>


Thanks,
Kris

Shawn M Moore

unread,
Jan 14, 2009, 11:05:24 AM1/14/09
to hivemin...@googlegroups.com
On Tue, Jan 13, 2009 at 07:20:02PM -0800, wka wrote:
>
> (Given all of the spam in this group lately, I don't know if anyone is
> reading, but if anyone is...)

Hi Kris,

There are indeed some humans still kicking around here. :)

> I would expect some sort of error when updating the deleted task, just
> like the 404 returned when trying to read it. Instead, the update
> creates a new task.

In Jifty::Plugin::REST::Dispatcher we have the following code:

if ( not $rec->id ) {
abort(404) if $prefix eq 'Delete';
$prefix = 'Create' if $prefix eq 'Update';
}

This code was last touched two years ago, probably when the plugin was
initially written.

Jesse: Instead of adjusting $prefix to Create, could we abort(404) if
the record we're trying to update doesn't exist? It would be a change in
behavior and could break an app that depends on it. But I don't know of
any that do depend on this.

> Thanks,
> Kris

Shawn

Jesse Vincent

unread,
Jan 14, 2009, 11:40:02 AM1/14/09
to Shawn M Moore, hivemin...@googlegroups.com
The current code looks insane. Please fix it.

--
Sent from my Android phone with K-9. Please excuse my brevity.

Shawn M Moore

unread,
Jan 15, 2009, 10:16:57 AM1/15/09
to hivemin...@googlegroups.com
Hey again Kris,

On Tue, Jan 13, 2009 at 07:20:02PM -0800, wka wrote:

> # Attempt to update it
>
> curl -X PUT -d summary=test2 -b JIFTY_SID_HIVEMINDER=<COOKIE>
> http://hiveminder.com/=/model/Task/id/584435.xml

This should now throw a 404, and when following your steps it did. Want
to try your application again? :)

> Thanks,
> Kris

Shawn

wka

unread,
Jan 17, 2009, 3:09:31 PM1/17/09
to Hiveminder API Hackers
It is working just as you describe, now.

Thank you,
Kris
Reply all
Reply to author
Forward
0 new messages