I've got another problem with finance, pset7, CS50x.

When I check50 my solution, I get an error (see first of image) claiming that a KeyError (on a field named "date_time") occurs when performing a BUY action.

Error message from check50: exception raised in application

As far as i can see, that error usually occurs when looking up items in a dictionary.

The only time I use "date_time" as a dict key (see second image) is in the code for the history page.

Using date_time as a dict key

And in the third image you can see that my history page does work as expected (on my side) after performing a BUY and a SELL.

Is check50 checking something which was not in the specifications at https://docs.cs50.net/2018/x/psets/7/finance/finance.html … ?

History showing date_time to be correctly entered into my transactions table.

  • Do you run update50 before compiling? – sk.76 Oct 19 '18 at 9:19
  • I didn't compile anything. But I always run update50 before executing flask run. And the application seems to run flawless at my side. --- I assume that check50 (where the error occurs) will run it at some place that has also updated correctly ... – Peter Pesch Oct 19 '18 at 9:22
  • Maybe the corresponding INSERT could give any hint? I don't think buy test calls your history. – Blauelf Oct 19 '18 at 9:25
  • As you can see from the second picture, check50 doesn't show the INSERT statement. I can show you the INSERT I see when buying in a couple of minutes. Let me start up the server ... – Peter Pesch Oct 19 '18 at 9:29
  • The INSERT statement I see is: INSERT INTO transactions (userid, transact_timestamp_utc, symbol, bought, price) VALUES (1, '2018-10-19 09:31:27', 'NFLX', 1, 346.71) (I implemented the UPDATE of the users table as a separate statement, which was issued just before. Apparently, the buy action still works flawlessly at my side. – Peter Pesch Oct 19 '18 at 9:34

I found the answer/solution!

Apart from that, I also found the reason for the exception that check50 reported:

  • My history-view had a field named Date_Time.
  • My SELECT-query selects that field as date_time.
  • The IDE's version of CS50's db.execute() correctly returns that column as indexed with date_time.
  • But apparently, check50's version of CS50's db.execute() seems to return that column as indexed with Date_Time ...

The exception disappeared after I changed the field-name in the View.

After solving that issue, I got another error on that same check:

New error message

So apparently check50 expects to see the \portfolio page after a successful BUY action. And also after a successful SELL action.

Which leads to an answer to my question:

Is check50 checking something which was not in the specifications at https://docs.cs50.net/2018/x/psets/7/finance/finance.html … ?


Yes. Apart from checking the specifications, check50 also checks that you show the portfolio page after each successful SELL or BUY action.

  • I thought you had a similar background to me. ( Database engineer ) ;-) – Cliff B Oct 25 '18 at 3:36
  • Not quite, I lack some of the technical knowledge. I work mainly with ETL, Data Warehouses and Datamarts. So I have to avoid thigns that won't perform in a database, but if I do run into performance issues I need help from a database engineer. That mostly happens when the tool tries to "improve" the ETL we designed into something which doesn't really work on the target DBMS. – Peter Pesch Oct 25 '18 at 5:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .