magfest / ubersystem

MAGFest's Ubersystem - handles ticketing, staffing, analytics, volunteers, and tons more
http://magfest.org
GNU Affero General Public License v3.0
48 stars 55 forks source link

volunteer checklist problem - food restrictions broken #1934

Open binary1230 opened 8 years ago

binary1230 commented 8 years ago

Mike P tripped this, not sure the circumstances. It looks like it might be when someone is trying to update food preferences on labs via the volunteer checklist probably (because staffer_id is set in the cherrypy session). It looks like it's trying to insert a second row with the same unique foreign attendee ID into the food_restrictions table.

2016-08-08 14:37:34,103 [ERROR] uber.server: Exception encountered
    Request: POST /uber/signups/food_restrictions HTTP/1.0
    Current admin user is: Michael P
    Request Params:
      sandwich_pref: 108096257
      csrf_token: [secret-removed]
      id: None
      freeform: 
    Session Params:
    dict_items([('paid_preregs', []), ('account_id', '[secret-removed]'), ('unpaid_preregs', OrderedDict()), ('staffer_id', '[secret-removed]'), ('csrf_token', '[secret-removed]'), ('job_defaults', defaultdict(<class 'dict'>, {'266227276': {'slots': 2, 'restricted': False, 'name': 'Light Tech (Shadow)', 'weight': 1.0, 'duration': 4, 'description': '', 'extra15': False}}))])
    Request Headers:
      USER-AGENT: Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
      ACCEPT-LANGUAGE: en-US,en;q=0.8
      ACCEPT-ENCODING: gzip, deflate, br
      ORIGIN: https://labs.uber.magfest.org
      CONNECTION: close
      Content-Length: 85
      REFERER: https://labs.uber.magfest.org/uber/signups/food_restrictions
      COOKIE: phpbb3_451kv_u=1; phpbb3_451kv_k=; phpbb3_451kv_sid=[secret-removed]; style_cookie=null; __utma=72935823.960070847.1441211037.1470409954.1470423031.23; __utmc=72935823; __utmz=72935823.1463235267.9.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); session_id=[secret-removed]
      Remote-Addr: 127.0.0.1
      ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
      CACHE-CONTROL: max-age=0
      Content-Type: application/x-www-form-urlencoded
      UPGRADE-INSECURE-REQUESTS: 1
      HOST: labs.uber.magfest.org
    Traceback (most recent call last):
      File "/usr/local/uber/plugins/uber/uber/decorators.py", line 211, in with_session
        retval = func(*args, session=session, **kwargs)
      File "/usr/local/uber/plugins/uber/uber/decorators.py", line 324, in with_restrictions
        return func(*args, **kwargs)
      File "/usr/local/uber/plugins/uber/uber/decorators.py", line 273, in with_rendering
        result = func(*args, **kwargs)
      File "/usr/local/uber/plugins/uber/uber/decorators.py", line 140, in with_check
        return func(self, *args, **kwargs)
      File "/usr/local/uber/plugins/uber/uber/site_sections/signups.py", line 31, in food_restrictions
        raise HTTPRedirect('index?message={}', 'Your dietary restrictions have been recorded')
    uber.utils.HTTPRedirect: (['http://labs.uber.magfest.org/uber/signups/index?message=Your%20dietary%20restrictions%20have%20been%20recorded'], 302)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
        context)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/engine/default.py", line 442, in do_execute
        cursor.execute(statement, parameters)
    psycopg2.IntegrityError: duplicate key value violates unique constraint "food_restrictions_attendee_id_key"
    DETAIL:  Key (attendee_id)=([secret-removed]) already exists.

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
      File "/usr/local/uber/env/lib/python3.4/site-packages/cherrypy/_cprequest.py", line 670, in respond
        response.body = self.handler()
      File "/usr/local/uber/env/lib/python3.4/site-packages/cherrypy/lib/encoding.py", line 217, in __call__
        self.body = self.oldhandler(*args, **kwargs)
      File "/usr/local/uber/env/lib/python3.4/site-packages/cherrypy/_cpdispatch.py", line 61, in __call__
        return self.callable(*self.args, **self.kwargs)
      File "/usr/local/uber/plugins/uber/uber/decorators.py", line 196, in with_timing
        return func(*args, **kwargs)
      File "/usr/local/uber/plugins/uber/uber/decorators.py", line 187, in with_caching
        return func(*args, **kwargs)
      File "/usr/local/uber/plugins/uber/uber/decorators.py", line 215, in with_session
        session.commit()
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/orm/session.py", line 790, in commit
        self.transaction.commit()
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/orm/session.py", line 392, in commit
        self._prepare_impl()
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/orm/session.py", line 372, in _prepare_impl
        self.session.flush()
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/orm/session.py", line 2004, in flush
        self._flush(objects)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/orm/session.py", line 2122, in _flush
        transaction.rollback(_capture_exception=True)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__
        compat.reraise(exc_type, exc_value, exc_tb)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/util/compat.py", line 182, in reraise
        raise value
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/orm/session.py", line 2086, in _flush
        flush_context.execute()
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/orm/unitofwork.py", line 373, in execute
        rec.execute(self)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/orm/unitofwork.py", line 532, in execute
        uow
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/orm/persistence.py", line 174, in save_obj
        mapper, table, insert)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/orm/persistence.py", line 729, in _emit_insert_statements
        execute(statement, multiparams)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 914, in execute
        return meth(self, multiparams, params)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection
        return connection._execute_clauseelement(self, multiparams, params)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 1010, in _execute_clauseelement
        compiled_sql, distilled_params
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
        context)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 1332, in _handle_dbapi_exception
        exc_info
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/util/compat.py", line 188, in raise_from_cause
        reraise(type(exception), exception, tb=exc_tb, cause=exc_value)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/util/compat.py", line 181, in reraise
        raise value.with_traceback(tb)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
        context)
      File "/usr/local/uber/env/lib/python3.4/site-packages/sqlalchemy/engine/default.py", line 442, in do_execute
        cursor.execute(statement, parameters)
    sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) duplicate key value violates unique constraint "food_restrictions_attendee_id_key"
    DETAIL:  Key (attendee_id)=([secret-removed]) already exists.
     [SQL: 'INSERT INTO food_restrictions (id, attendee_id, standard, sandwich_pref, freeform) VALUES (%(id)s, %(attendee_id)s, %(standard)s, %(sandwich_pref)s, %(freeform)s)'] [parameters: {'sandwich_pref': '108096257', 'standard': '', 'attendee_id': UUID('[secret-removed]'), 'id': UUID('[secret-removed]'), 'freeform': ''}]```
binary1230 commented 8 years ago

Also, same deal with some of the other ones like hotel requests:

psycopg2.IntegrityError: duplicate key value violates unique constraint "hotel_requests_attendee_id_key"
   DETAIL:  Key (attendee_id)=([secret-removed]) already exists.

I replaced the real attendee ID with [secret-removed] since that is sensitive info

bds002 commented 8 years ago

So this was discussed in Slack - There error is caused when an Admin account is logged into uber and you try to log in with your Volunteer account to do Checklist items. It is only going to affect Uber Admin accounts that also try to log in to the checklist items. I am ok with it erroring out with 2 different logins from the same computer / same browser, different tabs.

binary1230 commented 8 years ago

I don't know that this is actually the cause. I just tried to repro that exact thing on the staging server and had no luck.

It's definitely something though where the information is getting submitted twice, maybe some case where we're not detecting that something else already exists

kitsuta commented 8 years ago

Yeah, there's nothing obvious from looking at the code, either.

Did we import these tables to MAGLabs at any point? It's possible that, say, we have a column on the FoodRestriction table that has an attendee id, but we don't have the foreign key on that attendee to connect it with the food restriction. Foreign keys aren't in the database, after all.

If that's the case, we could fix this by changing this line: fr = attendee.food_restrictions or FoodRestrictions() to something that looks up the attendee's ID in the food restrictions table. Alternatively, we can try to figure out how to import the foreign keys.

binary1230 commented 8 years ago

don't recall importing anything, so not sure. from what I can see, this was only happening with Mike, and he's OK now so we can let this simmer for a bit.