Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forms example does not work #349

Closed
moshez opened this issue May 23, 2020 · 2 comments
Closed

Forms example does not work #349

moshez opened this issue May 23, 2020 · 2 comments

Comments

@moshez
Copy link
Contributor

moshez commented May 23, 2020

The example in https://github.com/twisted/klein/blob/3e6db246d1272bf6daa07fab00fc3b610c07b1fa/docs/introduction/codeexamples/forms.py does not work with current klein.

The first error is that there is no such thing as Field.integer. When corrected to Field.number, the example runs, but when submitting the form, the result is a traceback:

2020-05-23 13:28:40-0700 [-] Unhandled Error                           [13/1985]        Traceback (most recent call last):
          File "/home/moshez/src/ppb-game/build/penguin/lib/python3.7/site-packa
ges/klein/_app.py", line 250, in _f                                                         return _call(instance, f, request, *a, **kw)     
          File "/home/moshez/src/ppb-game/build/penguin/lib/python3.7/site-packa
ges/klein/_app.py", line 55, in _call                                                       result = __klein_f__(*args, **kwargs)
          File "/home/moshez/src/ppb-game/build/penguin/lib/python3.7/site-packa
ges/twisted/internet/defer.py", line 1613, in unwindGenerator                               return _cancellableInlineCallbacks(gen)                                       File "/home/moshez/src/ppb-game/build/penguin/lib/python3.7/site-packa
ges/twisted/internet/defer.py", line 1529, in _cancellableInlineCallbacks                   _inlineCallbacks(None, g, status)
        --- <exception caught here> ---
          File "/home/moshez/src/ppb-game/build/penguin/lib/python3.7/site-packa
ges/twisted/internet/defer.py", line 1418, in _inlineCallbacks
            result = g.send(result)
          File "/home/moshez/src/ppb-game/build/penguin/lib/python3.7/site-packa
ges/klein/_requirer.py", line 153, in router
            **injected
          File "/home/moshez/src/ppb-game/build/penguin/lib/python3.7/site-packa
ges/klein/_app.py", line 55, in _call
            result = __klein_f__(*args, **kwargs)
          File "/home/moshez/src/ppb-game/build/penguin/lib/python3.7/site-packa
ges/twisted/internet/defer.py", line 1604, in unwindGenerator
            gen = f(*args, **kwargs)
        builtins.TypeError: mymethod() missing 1 required positional argument: '
request'

In the example, the routed and style decorator should be switched:

@requirer.require(
    style.routed(
        app.route("/", methods=["POST"]),
        tags.h1('u did it: ', slot("an-form-arg"))
    ),
    foo=Field.number(minimum=3, maximum=10), bar=Field.text(),
)
def postHandler(foo, bar):
    return {"an-form-arg": foo}
@glyph glyph closed this as completed in 6309dd6 May 24, 2020
glyph added a commit that referenced this issue May 24, 2020
Fix #349: Update forms example to run correctly
@glyph
Copy link
Member

glyph commented May 24, 2020

@moshez We should fix it so that they work in either order. Can you file a new bug?

@moshez
Copy link
Contributor Author

moshez commented May 24, 2020

Opened #351

wsanchez added a commit that referenced this issue May 27, 2020
* master: (26 commits)
  [requires.io] dependency update
  Fix #349: Update forms example to run correctly
  [requires.io] dependency update
  [requires.io] dependency update
  [requires.io] dependency update
  Don't use "l" as a variable name.
  [requires.io] dependency update
  [requires.io] dependency update
  [requires.io] dependency update
  [requires.io] dependency update
  [requires.io] dependency update
  [requires.io] dependency update
  [requires.io] dependency update
  [requires.io] dependency update
  [requires.io] dependency update
  [requires.io] dependency update
  mock 4 dropped Py2
  hypothesis5 drops Py2
  Update dependencies
  Don't have two tw192's
  ...

# Conflicts:
#	.travis.yml
#	tox.ini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants