Skip to content
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

cache of Form Validation for Applications sometimes incorrect #2165

Closed
dannyroberts opened this issue Dec 23, 2013 · 0 comments
Closed

cache of Form Validation for Applications sometimes incorrect #2165

dannyroberts opened this issue Dec 23, 2013 · 0 comments

Comments

@dannyroberts
Copy link
Member

Background

screen shot 2013-12-23 at 2 06 02 pm

In the Application builder, all forms get passed through an external java program that runs the validation that CommCare mobile runs, and it'll tell you things like whether there's a circular dependency in your form logic, or if (as in the image) if you have a "select" question that has no options, etc.

Since this requires loading the form from couch (it's stored as an attachment) and then passing the form to an external process, it's actually quite time consuming, and since we want that to appear as an error message to the user, it's required on a bunch of page-loads, so we cache the result rather than running it each time.

Overview of Current Solution

Forms have a property called source who's setter and getter are controlled by a "property descriptor": https://github.com/dimagi/commcare-hq/blob/master/corehq/apps/app_manager/models.py#L330 (probably not necessary to understand deeply, but for reference: http://docs.python.org/2/howto/descriptor.html). The source XML itself is then saved as an attachment on the application instead of in the json.

When form.source is set, the validation_cache reset here https://github.com/dimagi/commcare-hq/blob/master/corehq/apps/app_manager/models.py#L261. This validation_cache is in turn controlled by another property descriptor (https://github.com/dimagi/commcare-hq/blob/master/corehq/apps/app_manager/models.py#L331) and essentially just saves that value to another couch doc. (I think we originally didn't want saving this validation to have be be done at the same time as saving the application, which is why it's in a separate doc.)

The main place where validation_cache is used is in the function validate_form.

The Problem with Current Solution

Other than just being overly complicated, it appears that some part of it recently sprung a leak, as we're finding that some people's forms are showing up with a clean validation cache, but the form actually has problems.

The Proposed Solution

(This is me brainstorming now. I wanted to say md5 it and then use that as the cache key, but that requires having access to the form, and getting the form from the db is half the issue. Then I wanted to say, well then save the md5 of the form in the form json, inside FormSource.__set__, but I'm worried that then whatever the current issue is would continue to be an issue, since we haven't figured out what's causing the incorrect cache. It might work though, so perhaps still worth a try.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant