WebApp Error: <class 'sqlalchemy.orm.exc.FlushError'>: Instance <ChangesetComment at 0x7f4da060a110> has a NULL identity key. If this is an auto-generated value, check that the database table allows generation of new primary key values,

Issue #806 invalid
Vijeth Shetty created an issue

I moved Rhodecode from Sqlite to MYSql and also in the Process upgraded from 1.5.2.to 1.5.4 . So the Journal doesn't get updated . I have 395655 rows in 'user_logs' table . when i try to do hg push I get "500" error .Here is my log for the same when it tries to write to the table . I also enabled AUTO INCREMENT for user_log _id which worked but i ended up with ids with odd number increment , instead of 1,2,3 it ends up 1,3,5, or 2,4,6. Its a similar issue when i tried adding up comment . I have attached a screenshot for the same .

Module rhodecode.controllers.changeset:2 in comment

Module rhodecode.lib.utils:759 in jsonify

<<      pylons = get_pylons(args)
           pylons.response.headers['Content-Type'] = 'application/json; charset=utf-8'
           data = func(*args, **kwargs)
           if isinstance(data, (list, tuple)):
               msg = "JSON responses with Array envelopes are susceptible to " \
>>  data = func(*args, **kwargs)
Module rhodecode.controllers.changeset:340 in comment

<<              line_no=request.POST.get('line'),
                                  if status and change_status else None)
>>  if status and change_status else None)
Module rhodecode.model.comment:100 in create

<<          self.sa.add(comment)

               # make notification
>>  self.sa.flush()
Module sqlalchemy.orm.session:1718 in flush

<<          try:
                   self._flushing = True
                   self._flushing = False
>>  self._flush(objects)
Module sqlalchemy.orm.session:1793 in _flush

<<              self.dispatch.after_flush(self, flush_context)


                   # useful assertions:
>>  flush_context.finalize_flush_changes()
Module sqlalchemy.orm.unitofwork:347 in finalize_flush_changes

<<                  # if listonly:
                       #   debug... would like to see how many do this

       class IterateMappersMixin(object):
>>  self.session._register_newly_persistent(state)
Module sqlalchemy.orm.session:1316 in _register_newly_persistent

<<                      "generated values.  Ensure also that this flush() is "
                           "not occurring at an inappropriate time, such as within "
                           "a load() event." % mapperutil.state_str(state)
>>  "a load() event." % mapperutil.state_str(state)
FlushError: Instance <ChangesetComment at 0x7f4da060a110> has a NULL identity key. If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is configured to expect these generated values. Ensure also that this flush() is not occurring at an inappropriate time, such as within a load() event.

CGI Variables   
CONTENT_TYPE     'application/x-www-form-urlencoded; charset="utf-8"'   
HTTP_ACCEPT  'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'  
HTTP_ACCEPT_ENCODING     'gzip, deflate'    
HTTP_ACCEPT_LANGUAGE     'en-US,en;q=0.5'   
HTTP_COOKIE  '__utma=254890583.54813714.1362697243.1362697243.1363131330.2; __utmz=254890583.1362697243.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _mkto_trk=id:509-APS-230&token:_mch-apptio.com-1362697243362-17033; _vis_opt_s=1%7C; _vis_opt_exp_2_combi=1; _vis_opt_exp_2_goal_1=1; rhodecode=62bede597d434e85b8e427d8c0be8d58'    
HTTP_HOST    'hg.apptio.com'    
HTTP_REFERER     'https://hg.apptio.com/apps-build/changeset/3fdd6a42013447fd3f3b4e414ab3232d971ed8d5'  
HTTP_USER_AGENT  'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0' 
HTTP_X_FORWARDED_HOST    'hg.apptio.com'    
HTTP_X_FORWARDED_SERVER  'hg.apptio.com'    
PATH_INFO    '/apps-build/changeset/3fdd6a42013447fd3f3b4e414ab3232d971ed8d5/comment'   
SERVER_NAME  'localhost'    
SERVER_PORT  '5000' 
SERVER_SOFTWARE  'waitress' 
WSGI Variables  
application  <beaker.middleware.SessionMiddleware object at 0x2d5b950>  
beaker.get_session   <bound method SessionMiddleware._get_session of <beaker.middleware.SessionMiddleware object at 0x2d5b950>> 
beaker.session   {'_authentication_token': '34d650364fd7212c6dc677dba3a39aadfd7670a0', 'rhodecode_user': {'username': u'vshetty', 'is_authenticated': True, 'user_id': 8}, '_accessed_time': 1364012701.0847161, '_creation_time': 1363724740.5356171}  
paste.registry   <paste.registry.Registry object at 0x7f4d9c70af90> 
paste.throw_errors   True   
pylons.action_method     <bound method ChangesetController.comment of <rhodecode.controllers.changeset.ChangesetController object at 0x7f4d9e8a4490>>   
pylons.controller    <rhodecode.controllers.changeset.ChangesetController object at 0x7f4d9e8a4490> 
pylons.environ_config    {'session': 'beaker.session', 'cache': 'beaker.cache'} 
pylons.pylons    <pylons.util.PylonsContext object at 0x7f4d9e1534d0>   
pylons.routes_dict   {'action': u'comment', 'controller': u'changeset', 'revision': u'3fdd6a42013447fd3f3b4e414ab3232d971ed8d5', 'repo_name': u'apps-build'}    
routes.route     <routes.route.Route object at 0x281cad0>   
routes.url   <routes.util.URLGenerator object at 0x7f4d91dcadd0>    
webob._parsed_post_vars  (MultiDict([('changeset_status', 'not_reviewed'), ('text', 'c'), ('save', 'Comment')]), <FakeCGIBody at 0x7f4d619e2c50 viewing MultiDict([('ch...t')])>)   
webob._parsed_query_vars     (GET([]), '')  
webob.adhoc_attrs    {'errors': 'ignore', 'user': <AuthUser('id:8:vshetty|True')>, 'language': 'en-us'} 
webob.is_body_readable   True   
webob.is_body_seekable   False  
wsgi process     'Multithreaded'    
wsgi._org_proto  'http' 
wsgi.file_wrapper    <class 'waitress.buffers.ReadOnlyFileBasedBuffer'> 
wsgiorg.routing_args     (<routes.util.URLGenerator object at 0x7f4d91dcadd0>, {'action': u'comment', 'controller': u'changeset', 'revision': u'3fdd6a42013447fd3f3b4e414ab3232d971ed8d5', 'repo_name': u'apps-build'}) 

Comments (3)

  1. Marcin Kuzminski repo owner

    It looks like an PK issues with mysql (btw what version of mysql are you using ?), please check your database setup. Try a fresh db installation for comparison

  2. Log in to comment