FinalsClub / karmaworld

KarmaNotes.org v3.0
GNU Affero General Public License v3.0
7 stars 6 forks source link

Course creation fails on non-valid URL field input #346

Closed AndrewMagliozzi closed 10 years ago

AndrewMagliozzi commented 10 years ago

School: Harvard University course name: anything honeypot: instructor: mr smith instructor email: smith@gmail.com url: fsadfsdaf

This throws a 500 error on the POST

AndrewMagliozzi commented 10 years ago

This seems to be a result of the honeypot

JHilker commented 10 years ago

KeyError at / 'honeypot' Request Method: POST Request URL: http://localhost:8000/ Django Version: 1.5.5 Exception Type: KeyError Exception Value:
'honeypot' Exception Location: /private/var/www/karmaworld/karmaworld/apps/courses/views.py in form_invalid, line 72 Python Executable: /private/var/www/karmaworld/venv/bin/python Python Version: 2.7.5 Python Path:
['/private/var/www/karmaworld', '/private/var/www/karmaworld/venv/lib/python27.zip', '/private/var/www/karmaworld/venv/lib/python2.7', '/private/var/www/karmaworld/venv/lib/python2.7/plat-darwin', '/private/var/www/karmaworld/venv/lib/python2.7/plat-mac', '/private/var/www/karmaworld/venv/lib/python2.7/plat-mac/lib-scriptpackages', '/private/var/www/karmaworld/venv/lib/python2.7/lib-tk', '/private/var/www/karmaworld/venv/lib/python2.7/lib-old', '/private/var/www/karmaworld/venv/lib/python2.7/lib-dynload', '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/private/var/www/karmaworld/venv/lib/python2.7/site-packages', '/private/var/www/karmaworld/karmaworld/apps', '/private/var/www/karmaworld/karmaworld']

btbonval commented 10 years ago

Looking at the code, I made the assumption that form.errors['honeypot'] will always be defined, even if empty. https://github.com/FinalsClub/karmaworld/blob/a19007eba919017445625562ab19534b7b285c76/karmaworld/apps/courses/views.py#L72

But it is only set if there are actually errors. https://github.com/FinalsClub/karmaworld/blob/a19007eba919017445625562ab19534b7b285c76/karmaworld/apps/courses/forms.py#L37

This begs the question of why it ever works, right? If there are no honeypot errors, then honeypot should be blank, which should cause error 500 and a course could never be made. But we don't see that.

how bizarre.

btbonval commented 10 years ago

derp. form_invalid is called if there is an error. If there is no error, form_invalid is not called, and so that line 72 is not executed.

okay so I just have to conditionally set the hard coded error passthrough hacky thing.

btbonval commented 10 years ago

Sort buttons are weirded out. Probably my static files are out of date. anyway, flubbed up URL but made everything else solid and I got the right error in the right place. Created a course with a good URL and everything kept on working.

I added a note just to make sure I didn't break that feature.

Looks good, pushing to beta and then prod. It's a change to a single line so it shouldn't be far reaching.