Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Initial support for funding-goals-over-time; #141 #745

Merged
merged 5 commits into from
Apr 3, 2013

Conversation

dowski
Copy link
Contributor

@dowski dowski commented Mar 18, 2013

This is for issue #141.

TODO:

  • Script for migration of current goal field data to goals table entry for each user
  • Edit schema to drop goal from participant table (safer after migration is complete)

I might be missing some places where goals are referenced. I tried to keep the API the same so hopefully it won't matter, but who knows, I've never used SQLAlchemy before.

Christian Wyglendowski added 2 commits March 18, 2013 02:17
TODO:
 * Tests
 * Migration of current `goal` field to goals table entry for each user
 * Removing the `goal` column from participant
@dowski
Copy link
Contributor Author

dowski commented Mar 19, 2013

Let's go tests.

@dowski
Copy link
Contributor Author

dowski commented Mar 19, 2013

Current Status:

...........................................................E...........................................................................E.....E.....................................
======================================================================
ERROR: test_fake_data (test_fake_data.TestFakeData)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/christian/src/gittip/www.gittip.com/tests/test_fake_data.py", line 18, in test_fake_data
    fake_data.populate_db(self.session, num_participants, num_tips)
  File "/home/christian/src/gittip/www.gittip.com/gittip/fake_data.py", line 93, in populate_db
    p = fake_participant()
  File "/home/christian/src/gittip/www.gittip.com/gittip/fake_data.py", line 51, in fake_participant
    claimed_time=faker.dateTimeThisYear()
  File "<string>", line 4, in __init__
  File "/home/christian/src/gittip/www.gittip.com/env/local/lib/python2.7/site-packages/sqlalchemy/orm/state.py", line 200, in _initialize_instance
    return manager.original_init(*mixed[1:], **kwargs)
  File "/home/christian/src/gittip/www.gittip.com/env/local/lib/python2.7/site-packages/sqlalchemy/ext/declarative/base.py", line 428, in _declarative_constructor
    setattr(self, k, kwargs[k])
AttributeError: can't set attribute

======================================================================
ERROR: test_anonymous_does_not_get_goal_if_user_regifts (test_public_json.Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/christian/src/gittip/www.gittip.com/tests/test_public_json.py", line 57, in test_anonymous_does_not_get_goal_if_user_regifts
    alice.goal = 0
AttributeError: can't set attribute

======================================================================
ERROR: test_anonymous_gets_user_goal_if_set (test_public_json.Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/christian/src/gittip/www.gittip.com/tests/test_public_json.py", line 75, in test_anonymous_gets_user_goal_if_set
    alice.goal = Decimal('1.00')
AttributeError: can't set attribute

----------------------------------------------------------------------
Ran 179 tests in 4.800s

FAILED (errors=3)

Christian Wyglendowski added 3 commits March 19, 2013 00:28
This is in part b/c the tests are failing when trying to set the goal
attribute of a participant. Setting that attribute now uses the current
db.session and adds a row to the goals table.
Previously it was NOT NULL. That was not right at all.
It's a descriptor that handles getting the latest value from Postgres
and adding new rows when the goal changes.
@dowski
Copy link
Contributor Author

dowski commented Mar 19, 2013

Current Status:

...................................................................................................................................................................................
----------------------------------------------------------------------
Ran 179 tests in 4.903s

OK

@dowski
Copy link
Contributor Author

dowski commented Mar 19, 2013

So liberal review of the code is in order, but tests are passing and the goals table contents for my participant looks reasonable.

gittip=# select * from goals where participant = 'dowskimania';
 id |             ctime             |             mtime             | participant |  amount
----+-------------------------------+-------------------------------+-------------+-----------
  1 | 2013-03-18 06:09:20.749007+00 | 2013-03-18 06:09:20.749007+00 | dowskimania |  33333.00
  2 | 2013-03-18 06:09:20.749007+00 | 2013-03-18 06:11:24.408643+00 | dowskimania |  33333.00
  3 | 2013-03-18 06:09:20.749007+00 | 2013-03-18 06:11:30.486644+00 | dowskimania |     33.00
  4 | 2013-03-18 06:09:20.749007+00 | 2013-03-18 06:13:57.464278+00 | dowskimania |    333.00
  5 | 2013-03-18 06:09:20.749007+00 | 2013-03-18 06:15:05.326914+00 | dowskimania |      0.00
  6 | 2013-03-18 06:09:20.749007+00 | 2013-03-18 06:15:17.79534+00  | dowskimania |      1.00
  7 | 2013-03-18 06:09:20.749007+00 | 2013-03-19 04:09:48.094323+00 | dowskimania |     44.00
  9 | 2013-03-18 06:09:20.749007+00 | 2013-03-19 04:14:12.163679+00 | dowskimania |
 10 | 2013-03-18 06:09:20.749007+00 | 2013-03-19 04:14:18.277217+00 | dowskimania |      0.00
 11 | 2013-03-18 06:09:20.749007+00 | 2013-03-19 04:14:28.948045+00 | dowskimania | 999999.00
(10 rows)

@dowski
Copy link
Contributor Author

dowski commented Mar 19, 2013

@whit537 suggests adding the migration code to schema.sql.

@chadwhitacre
Copy link
Contributor

I'm getting a 500 on profile pages from this, both my own and others. For some reason I'm not getting a traceback in the browser(?).

pid-55766 thread-4334317568 (CP Server Thread-7)     res = self.most_recent_goal(participant)
pid-55766 thread-4334317568 (CP Server Thread-7)   File "/Users/whit537/personal/gittip/www.gittip.com/gittip/models/participant.py", line 145, in most_recent_goal
pid-55766 thread-4334317568 (CP Server Thread-7)     return query.first()
pid-55766 thread-4334317568 (CP Server Thread-7)   File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2181, in first
pid-55766 thread-4334317568 (CP Server Thread-7)     ret = list(self[0:1])
pid-55766 thread-4334317568 (CP Server Thread-7)   File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2048, in __getitem__
pid-55766 thread-4334317568 (CP Server Thread-7)     return list(res)
pid-55766 thread-4334317568 (CP Server Thread-7)   File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2252, in __iter__
pid-55766 thread-4334317568 (CP Server Thread-7)     return self._execute_and_instances(context)
pid-55766 thread-4334317568 (CP Server Thread-7)   File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2267, in _execute_and_instances
pid-55766 thread-4334317568 (CP Server Thread-7)     result = conn.execute(querycontext.statement, self._params)
pid-55766 thread-4334317568 (CP Server Thread-7)   File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 664, in execute
pid-55766 thread-4334317568 (CP Server Thread-7)     params)
pid-55766 thread-4334317568 (CP Server Thread-7)   File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 764, in _execute_clauseelement
pid-55766 thread-4334317568 (CP Server Thread-7)     compiled_sql, distilled_params
pid-55766 thread-4334317568 (CP Server Thread-7)   File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 878, in _execute_context
pid-55766 thread-4334317568 (CP Server Thread-7)     context)
pid-55766 thread-4334317568 (CP Server Thread-7)   File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 871, in _execute_context
pid-55766 thread-4334317568 (CP Server Thread-7)     context)
pid-55766 thread-4334317568 (CP Server Thread-7)   File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 320, in do_execute
pid-55766 thread-4334317568 (CP Server Thread-7)     cursor.execute(statement, parameters)
pid-55766 thread-4334317568 (CP Server Thread-7) ProgrammingError: (ProgrammingError) relation "goals" does not exist
pid-55766 thread-4334317568 (CP Server Thread-7) LINE 2: FROM goals
pid-55766 thread-4334317568 (CP Server Thread-7)              ^
pid-55766 thread-4334317568 (CP Server Thread-7)  'SELECT DISTINCT ON (goals.participant) goals.id AS goals_id, goals.ctime AS goals_ctime, goals.mtime AS goals_mtime, goals.participant AS goals_participant, goals.amount AS goals_amount \nFROM goals \nWHERE %(param_
1)s = goals.participant ORDER BY goals.participant, goals.mtime DESC \n LIMIT %(param_2)s' {'param_1': u'Timmothygpo', 'param_2': 1}
InternalError('(InternalError) current transaction is aborted, commands ignored until end of transaction block\n',)
Traceback (most recent call last):
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/cheroot/server.py", line 979, in communicate
    req.respond()
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/cheroot/server.py", line 807, in respond
    self.server.gateway(self).respond()
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/cheroot/wsgi.py", line 34, in respond
    response = self.req.server.wsgi_app(self.env, self.start_response)
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/aspen/website.py", line 38, in __call__
    response = self.handle_safely(request)
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/aspen/website.py", line 70, in handle_safely
    response = self.do_outbound(response)
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/aspen/website.py", line 203, in do_outbound
    response = self.hooks.run('outbound', response)  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/aspen/hooks/__init__.py", line 18, in run    thing = func(thing) or thing  File "/Users/whit537/personal/gittip/www.gittip.com/gittip/authentication.py", line 46, in outbound
    user = User.from_session_token(user.session_token)
  File "/Users/whit537/personal/gittip/www.gittip.com/gittip/models/user.py", line 25, in from_session_token
    user = User.query.filter(User.session_token.op('=')(token)).first()
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2181, in first
    ret = list(self[0:1])
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2048, in __getitem__
    return list(res)
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2252, in __iter__
    return self._execute_and_instances(context)
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2267, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 664, in execute
    params)
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 764, in _execute_clauseelement
    compiled_sql, distilled_params
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 878, in _execute_context
    context)
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 871, in _execute_context
    context)
  File "/Users/whit537/personal/gittip/www.gittip.com/env/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 320, in do_execute
    cursor.execute(statement, parameters)
InternalError: (InternalError) current transaction is aborted, commands ignored until end of transaction block
 'SELECT participants.id AS participants_id, participants.statement AS participants_statement, participants.stripe_customer_id AS participants_stripe_customer_id, participants.last_bill_result AS participants_last_bill_result, participants.session_token AS participants_session_token, participants.session_expires AS participants_session_expires, participants.ctime AS participants_ctime, participants.claimed_time AS participants_claimed_time, participants.is_admin AS participants_is_admin, participants.balance AS participants_balance, participants.pending AS participants_pending, participants.anonymous AS participants_anonymous, participants.balanced_account_uri AS participants_balanced_account_uri, participants.last_ach_result AS participants_last_ach_result, participants.is_suspicious AS participants_is_suspicious \nFROM participants \nWHERE participants.session_token = %(session_token_1)s \n LIMIT %(param_1)s' {'param_1': 1, 'session_token_1': u'7dd8d9850539456da057b4b2150c6e13'}

We should write a test to catch this and then fix it.

@dowski
Copy link
Contributor Author

dowski commented Mar 19, 2013

Isn't this the meat of it: ProgrammingError: (ProgrammingError) relation "goals" does not exist?

@chadwhitacre
Copy link
Contributor

Derp-de-derp. Don't mind me! :)

@chadwhitacre chadwhitacre merged commit 0aa18a6 into gratipay:master Apr 3, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants