gcv / appengine-magic

A library designed to make it easy to use Google App Engine from Clojure
MIT License
341 stars 49 forks source link

Form params seem not to work, in dev environment only, after AppEngine 1.5+ #45

Open drcode opened 13 years ago

drcode commented 13 years ago

Hi everyone- I had posted a couple of months ago about an issue I had after upgrading to AppEngine 1.5+. The issue seems to persist with the latest appengine-magic, though the problem could also be due to a bug in ring, hiccup, or for that matter my java/jetty environment.

The app works fine when pushed into production. I have pushed a minimal app that reproduces the problem to http://formbug.appspot.com/. If you enter a username and submit it, it will echo it back on the followup page, as it should. When I try it in the dev environment however, it doesn't work, even though it worked fine on AppEngine 1.4.x. In that case, I can see the forms param properly submitted via the browser, but never seems to appear in the request object in my defroutes. Therefore, no matter what is typed into the form, the echoed result is always "The username is ".

I should point out that I've done some relatively complex development with AppEngine 1.5+ and appengine-magic and everything is working perfectly for me except for this one isolated issue.

I already tried digging into ring/hiccup/appengine-magic to see if I could find an exact cause and create a patch, but there is enough going on here that I have a hard time pinning down the cause of the issue (but I plan to look into this some more)

Here is the core.clj for my test app:

(ns formbug.core
  (:use [compojure.core :only [defroutes GET POST PUT DELETE ANY]]
        [ring.middleware.params :only [wrap-params]])
  (:require [appengine-magic.core :as ae]))

(defroutes formbug-app-handler
  (GET "/" [req]
       "<form name='input' action='post_url' method='post'>
Username: <input type='text' name='user' />
<input type='submit' value='Submit' />
</form>")
  (POST "/post_url" [user]
        {:status 200
         :headers {"Content-Type" "text/plain"}
         :body (str "the username is " user)}
        ))

(ae/def-appengine-app formbug-app
  (-> #'formbug-app-handler
      wrap-params))    

Here is my project.clj:

(defproject formbug "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [[org.clojure/clojure "1.2.1"]
                 [org.clojure/clojure-contrib "1.2.0"]
                 [hiccup "0.3.6"]
                 [compojure "0.6.4"]]
  :dev-dependencies [[appengine-magic "0.4.4"]])        

Since this might conceivably be environment-related, here are my dev box specs:

 Ubuntu 11.04
 AppEngine Release: 1.5.3
 Java(TM) SE Runtime Environment (build 1.7.0-b147)
 Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode)

If any of you happen to know why this is failing, please let me know. I realize it may not actually be an appengine-magic issue. I will keep investigating on my end, as well.

gcv commented 13 years ago

I tried your example, and it works fine for me in the interactive REPL (both as lein swank and lein repl). Does the bug only occur with dev-appserver.sh and lein appengine-dev-appserver?

If so, then you have run into this problem: http://stackoverflow.com/questions/6659657/issues-with-getting-both-post-and-get-http-parameters-in-appengine-magic-0-4-3-co (see also my first reply to https://github.com/gcv/appengine-magic/issues/28).

The short explanation: the App Engine SDK changed something between 1.4.x and 1.5.0, and dev-appserver.sh can no longer deal with GET or POST parameters. I haven't had time to investigate this, but I also don't experience this problem because I (almost) never use dev-appserver.sh.

I'm really curious about appengine-magic workflows which do not use the interactive REPL mode — I've always considered interactive development a primary selling feature of appengine-magic (and Lisp in general, to be honest). I understand that not everyone uses Emacs, but VimClojure should work.

gcv commented 13 years ago

Just to clarify: the bug you describe is completely reproducible on Mac OS with Java 6, using dev-appserver.sh. I don't think it's environment-related at all.

drcode commented 13 years ago

Yes, it only happens with dev-appserver.sh- Looks like I have run into a known issue. I will use the repl tools to avoid this- Thanks!