-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tax-Calculator 0.13.0 changes results names #735
Comments
@hdoupe said:
I don't know much about how TaxBrain saves run results in its database, but the two-step process makes logical sense. But several questions come to mind:
I don't know the answers, but these are the kind of questions you need to be asking yourselves. |
@martinholmer thanks for the advice. I'm going to try to do the full fix by replacing the variable names in the database. I'm giving myself to the end of the weekend. At that point, I'll have to move to the temporary fix I described above. I set up postgres on my computer and downloaded the test and production databases. I think this is a matter of cycling through the results and replacing the names. Once I fix the variable names, I should be able to push the edited database to heroku with the push command described in the heroku docs. @talumbau @brittainhard does this sound sensible? |
Would it be easier to build the backwards compatibility into tax-calculator? This is something we'll need to learn how to do eventually and will need to do more often after we release 1.0.0. I don't think it would be unreasonable to think about how to do it now. But if it is easier to deal with this in policybrain, that seems fine too. |
@hdoupe, can you give an example of what has changed? I'm assuming you mean a record entry has changed going forward and not a change in the name of a model attribute (ie a column name in the database). The latter is handled through migrations in Django, which is a pretty robust system at this point. |
@talumbau The keys in the For example, now when you call
In previous versions of Tax-Calculator, you would have gotten these keys:
This is a problem when we create the final tables in |
@MattHJensen asked:
It probably would be. I think we could do something like this in
|
Ah, I see what you are saying. My preferred solution would just be to create some kind of mapper function that would replace any keys of the old "allowed set" with the equivalent in the new set. You could then just make sure that any access to this attribute on a model was wrapped with this call. Or, perhaps you could even do a decorator on this attribute for the model that needs to be modified. The key point is that the function would only change the old values to the new, leaving the new values unchanged. Further, this solution would only involve doing additional computation when old data is accessed, instead of going through every record in the database to enforce this new policy. However, if you really wish to change every value in the database from the old keys to the new, what you propose is possible. I would just triple check that you have good backups of the production database, as you would always want to be able to restore to the original state should something go wrong. |
@talumbau said:
Several questions and a suggestion:
The suggestion: If, for example, 'ten_twenty' is a value in the database, then a simple SQL "UPDATE ... WHERE ..." command will change all the 'ten_twenty' values to '$10-20K'. Isn't this pretty easy to do? |
Django doesn't use raw database commands so you won't find that in the
repo. You can always look at the raw database directly obviously, but a
recommended way to interact with the underlying database of a Django
application is with "dbshell". More info about this can be found in the
Django tutorial.
To update the database directly, I would advise using the Postgres string
functions as described below. There can be unintended consequences of such
commands though so caution is advised.
https://stackoverflow.com/questions/5060526/postgresql-replace-all-instances-of-a-string-within-text-field
…On Fri, Nov 10, 2017 at 4:58 AM Martin Holmer ***@***.***> wrote:
@talumbau <https://github.com/talumbau> said:
However, if you really wish to change every value in the database from the
old keys to the new, what you propose is possible. I would just triple
check that you have good backups of the production database, as you would
always want to be able to restore to the original state should something go
wrong.
Several questions and a suggestion:
-
Where in the PolicyBrain repo is the database schema (that is, the SQL
"CREATE TABLE ..." commands)?
-
And where are the statements that store results in the database (that
is, SQL "INSERT ..." commands) and
where are the statements that retrieve results from the database (that
is, SQL "SELECT ..." commands)?
The suggestion:
If, for example, 'ten_twenty' is a value in the database, then a simple
SQL "UPDATE ... WHERE ..." command will change all the 'ten_twenty' values
to '$10-20K'. Isn't this pretty easy to do?
@hdoupe <https://github.com/hdoupe> @MattHJensen
<https://github.com/matthjensen>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#735 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABzcWtLg9-w3S4FJ4IeDaTrqW7m_tU9cks5s1EiGgaJpZM4QYxqE>
.
|
The more I think about this, the more I think that this is a high risk low reward situation. I'm not willing to compromise the database to clean up the codebase during this tax reform push. I think doing a full database update should be added to the ever-growing project and maintenance list that we have slated for the spring. @talumbau I like the idea of addressing this problem at the source with a decorator for the @talumbau and @martinholmer thank you for your input. |
Closed via #738 |
The names of the results columns were changed in PSLmodels/Tax-Calculator#1605. This is fine for future runs. However, the results from older runs will need to be handled in a special way until a better solution is found.
The best short term solution that I can think of is this: Keep a copy of both lists of names. The taxcalc version used in the old run is saved. So, we can use the old names for taxcalc version < 0.13.0.
In the long-term, we need to do a one-time update for the results database with the new variable names.
@martinholmer @GoFroggyRun do you have any thoughts on how to better handle this?
The text was updated successfully, but these errors were encountered: