-
Notifications
You must be signed in to change notification settings - Fork 0
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
Handle changes to schema selector fields #4
Comments
I think that I've fixed this, to some degree, but I've not done anything about migrating values between "before" and "after" schemas. @bjohare How were you imagining that this might work? I can see a couple of cases where things should just work (new schema has a non-required field the old schema doesn't; new schema lacks a field that was in the old schema), one where some action is required but things will work in all possible cases (new schema has a required field that the old schema doesn't, and there's a default value provided for the field), and a couple where there might be trouble (new schema has a required field that the old schema doesn't, with no default value provided; new schema has a field that occurs in the old schema, but with a different type that's not compatible with the current value in the field, or a choices list where the current value of the field doesn't occur). For the "trouble" cases, the temptation is to throw an exception somehow, but that's tricky because the schema change is only computed when you try to access the attributes or schema list for the underlying The alternative was somehow to monkey-patch assignments to model instance fields that are used as schema selectors, but that would quickly get horrible. Suppose that, for some platform domain entity, you use the project and organisation as schema selectors. If you update the entity's project, you need to recalculate the schemas. But also, if you update the project's organisation, you need to update the schemas. That means that you would need to maintain some sort of notification list for all of these things, which would quickly get complicated. It would also lead to "non-local" exceptions: if you modify a project's organisation, you could get exceptions saying that you're not allowed to make that change because it invalidates an attribute in a field in an instance of some model instance that has a foreign key to the project. That seems just wrong-oh. One option there is to say that schema updates when selectors change is only supported for selectors that aren't foreign keys, but that's naff. You might want to represent some sort of entity type as a foreign key into a type table, and you ought to be able to change those and have the schemas be recalculated without any drama. Any ideas how to untangle this knot? |
We had similar problems at UCL, here’s how we dealt with it:
Maybe we’re looking at this from the wrong point of view. Can we find a way to compute the differences between schemas when the schema is uploaded and provide a bunch of warnings whenever required? |
I think there is something to be said about providing a bunch of warnings whenever required as @oliverroick suggested. So in his examples:
Thoughts? |
I agree with this, and I've started implementing something to do it. The idea is to signal these problems when an attempt is made to save a model instance to the database by using Django's The only real problem with this is that it's difficult to do anything other than "allow silently" (don't throw an exception, so the save goes ahead as normal) or "disallow with error information" (throw an exception, save is aborted, exception information is passed back to the user showing which fields had problems). The last example you give, where the change is allowed but there's warning information, is a bit trickier to deal with. The only simple way to do it is to require the user to check explicitly whether there are schema migration warnings after attempting to save a model instance. If that's an acceptable approach, it should be easy to implement. To summarise, here's what I'm doing:
|
@ian-ross so in that case the errors would come back and the user would indicate they want to go forward anyway? I think that is an acceptable method. |
I think we might be using the word "user" in two different senses here. When I say "user" here, I mean a user of the After making a change to a Django model instance that leads to a schema update, there needs to be a check to see if there are any warnings, and if so, somehow to present those warnings to the "end user" in the platform UI. How that happens is up to the platform code, but the only mechanism I can think of that maintains a reasonable separation of concerns between the An additional thing that I could do is to add some code to allow a user of @oliverroick @bjohare What do you think? |
@ian-ross I was using the term user really broadly, but thinking about the API. I was picturing how it might be used on the front end, but what would have to happen on the backend. To me being able to check in advance would make sense from an API perspective. Then in the implementation in the platform that could be used to allow the user to say they didn't care about the warnings and to proceed. |
OK, that makes sense. I'll implement the in-advance check as well. Just writing a big pile of tests to make sure all the cases work right right now... |
I believe I now have a good solution for this. Changes to the schema selector fields of a model instance that has a I'm not sure what to do about incorporating this into the platform. These changes are included in version 0.1.8 of |
Currently, there's no special treatment for cases where the schema selectors for a model instance change and so the effective schema changes. There should be a facility to manage this sort of thing, including some mechanism for migrating values between the "before" and "after" schemas.
The text was updated successfully, but these errors were encountered: