title: TRACEBACK ERROR: NoResultFound: No row was found for one()
body: <p>I am trying to store form entries into my database. I have built a RESTful api for each entry in my db (I have also built a CRUD api for the database which makes POST and GET very simple to do for the most part). I have a JINJA2 HTML template that I am using from a Pyramid Web Interface for the user to interact with. I must admit, I am new to this and have been attempting to follow models in the pyramid <a href="http://pyramid-blogr.readthedocs.org/en/latest/blog_create_and_update_view_src.html" rel="nofollow">tutorial</a>s with no avail.</p>
  
  <p>The Error that I am getting is, what I believe, due to the route being entered as a <code>assessment.name</code> instead of an <code>id</code>. The API accepts assessment.name and assessment.id. But the parameter in the api.assessment_retrieve() is triggering the wrong thing.This is what I believe due to the <code>assessment = api.retrieve_assessment(request.route_url('assessment', id=id))</code> because when I place an actual <code>id</code> in the api, I get a result and all works.</p>
  
  <ol start="2">
  <li>There has to be a better method for grabbing the assessment_id from the <code>form</code> page, right? </li>
  </ol>
  
  <p>I have created an extra route_uri <code>/done</code> designated for the purposes of storing the form submission and keeping a user on the same page, instead of a 202 page &lt;-- but after as submission, I am still getting 202 (likely due to the HTTPCreate() function). </p>
  
  <ol start="2">
  <li>Is there a way to <code>return</code> routing the user back to the template?  </li>
  </ol>
  
  <p>Code:
  <strong>view.py</strong></p>
  
  <pre><code>@view_config(route_name='done', renderer='templates/assessment_form.jinja2')
  def form(request):
      with transaction.manager:
          username = request.params['username']
          firstname = request.params['firstname']
          lastname = request.params['lastname']
          email = request.params['email']
          user = api.create_user(username, firstname, lastname, email)
          assessment = (request.route_url('assessment', id=id)) # &lt;--- ISSUE
          assessment_results = api.create_assessment_results(user, assessment)
          transaction.commit()
          return HTTPCreated(location=request.route_url('user', id=id)) # &lt;-- redirect so the user keeps working on the form
  </code></pre>
  
  <p><strong>route uri</strong>
  (all the entities follow the user route example)</p>
  
  <pre><code>config.add_route('done', '/done')  
  
  config.add_route('users', '/users')
  config.add_route('user', '/users/{id:\d+}')
  </code></pre>
  
  <p><strong>template</strong></p>
  
  <pre><code>&lt;form method='POST' action='/done'&gt;
    &lt;dl class='user_form'&gt;
      &lt;dt&gt;&lt;label for = 'username'&gt; Username &lt;/label&gt;&lt;/dt&gt;
      &lt;dd&gt;{{ forms.input('username') }}&lt;/dd&gt;
      &lt;dt&gt;&lt;label for = 'firstname'&gt; Firstname &lt;/label&gt;&lt;/dt&gt;
      &lt;dd&gt;{{ forms.input('firstname') }}&lt;/dd&gt;
      &lt;dt&gt;&lt;label for = 'lastname'&gt; Lastname &lt;/label&gt;&lt;/dt&gt;
      &lt;dd&gt;{{ forms.input('lastname') }}&lt;/dd&gt;
      &lt;dt&gt;&lt;label for = 'email'&gt; Email &lt;/label&gt;&lt;/dt&gt;
      &lt;dd&gt;{{ forms.input('email') }}&lt;/dd&gt;
      &lt;dd&gt;&lt;input type="submit" name="submit" value="Submit" /&gt;&lt;/dd&gt; 
    &lt;/dl&gt;
  
    &lt;dl class='category_form'&gt;
      &lt;dt&gt;&lt;label for = 'category_rating_int'&gt; Situation Awareness &lt;/label&gt;&lt;/dt&gt;
      &lt;dd&gt;{{ forms.input('category_rating_int', type=category_rating_int) }}&lt;/dd&gt;
      &lt;dt&gt;&lt;label for = 'category_rating_int'&gt; Decision Making &lt;/label&gt;&lt;/dt&gt;
      &lt;dd&gt;{{ forms.input('category_rating_int', type=category_rating_int) }}&lt;/dd&gt;
      &lt;dt&gt;&lt;label for = 'category_rating_int'&gt; Teamwork and Communication  &lt;/label&gt;&lt;/dt&gt;
      &lt;dd&gt;{{ forms.input('category_rating_int', type=category_rating_int) }}&lt;/dd&gt;
      &lt;dt&gt;&lt;label for = 'category_rating_int'&gt; Leadership &lt;/label&gt;&lt;/dt&gt;
      &lt;dd&gt;{{ forms.input('category_rating_int', type=category_rating_int) }}&lt;/dd&gt;
      &lt;dd&gt;&lt;input type="submit" name="submit" value="Submit" /&gt;&lt;/dd&gt;
    &lt;/dl&gt;
  
   # more entities
  
    &lt;/form&gt;
  </code></pre>
  
  <p><strong>ERROR:</strong></p>
  
  <pre><code>2015-09-25 00:35:16,674 INFO  [sqlalchemy.engine.base.Engine][Dummy-4] SELECT assessments.assessment_id AS assessments_assessment_id, assessments.name AS assessments_name, assessments.text AS assessments_text, assessments.created_on AS assessments_created_on, assessments.edited AS assessments_edited, assessments.user_id AS assessments_user_id, assessments.video_id AS assessments_video_id 
  FROM assessments 
  WHERE assessments.name = ?
  2015-09-25 00:35:16,674 INFO  [sqlalchemy.engine.base.Engine][Dummy-4] ('http://0.0.0.0:6543/assessments/%3Cbuilt-in%20function%20id%3E',)
  2015-09-25 00:35:16,675 INFO  [sqlalchemy.engine.base.Engine][Dummy-4] ROLLBACK
  2015-09-25 00:35:16,677 ERROR [pyramid_debugtoolbar][Dummy-4] Exception at http://0.0.0.0:6543/done
  traceback url: http://0.0.0.0:6543/_debug_toolbar/exception?token=ead4c6c5a3d350eff925&amp;tb=4518219216
  Traceback (most recent call last):
    File "/usr/local/lib/python2.7/site-packages/pyramid_debugtoolbar-2.4.1-py2.7.egg/pyramid_debugtoolbar/toolbar.py", line 192, in toolbar_tween
      response = _handler(request)
    File "/usr/local/lib/python2.7/site-packages/pyramid_debugtoolbar-2.4.1-py2.7.egg/pyramid_debugtoolbar/panels/performance.py", line 57, in resource_timer_handler
      result = handler(request)
    File "/usr/local/lib/python2.7/site-packages/pyramid-1.5.7-py2.7.egg/pyramid/tweens.py", line 21, in excview_tween
      response = handler(request)
    File "/usr/local/lib/python2.7/site-packages/pyramid_tm-0.12-py2.7.egg/pyramid_tm/__init__.py", line 99, in tm_tween
      reraise(*exc_info)
    File "/usr/local/lib/python2.7/site-packages/pyramid_tm-0.12-py2.7.egg/pyramid_tm/__init__.py", line 80, in tm_tween
      response = handler(request)
    File "/usr/local/lib/python2.7/site-packages/pyramid-1.5.7-py2.7.egg/pyramid/router.py", line 163, in handle_request
      response = view_callable(context, request)
    File "/usr/local/lib/python2.7/site-packages/pyramid-1.5.7-py2.7.egg/pyramid/config/views.py", line 355, in rendered_view
      result = view(context, request)
    File "/usr/local/lib/python2.7/site-packages/pyramid-1.5.7-py2.7.egg/pyramid/config/views.py", line 501, in _requestonly_view
      response = view(request)
    File "/Users/ack/code/venv/NotssWEB/notssweb/views/views.py", line 32, in form
      assessment = api.retrieve_assessment(request.route_url('assessment', id=id))
    File "/usr/local/lib/python2.7/site-packages/notssdb/api/object.py", line 115, in retrieve_assessment
      filter(Assessment.name == something_unique).one()
    File "/usr/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2478, in one
      raise orm_exc.NoResultFound("No row was found for one()")
  NoResultFound: No row was found for one()
  </code></pre>