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

Add dummy object for validation mode. #341

Merged
merged 3 commits into from
Jun 13, 2019
Merged

Add dummy object for validation mode. #341

merged 3 commits into from
Jun 13, 2019

Conversation

mattcoley
Copy link
Collaborator

@mattcoley mattcoley commented Jun 12, 2019

If we are in validation mode and we have a zero-size loop, we used to convert [] to [0] so we can validate the for loop body by resolving it. The issue is as so looking at some typical code:

{% for test in get_objects() %}
 {{ test.property }}
 {{ test.numProperty + 10 }}
{% endfor %}

If get_objects() returns an empty list, we force test to be 0 which will cause validation errors in the for loop body where it expects a different object type returned from get_objects().

The best solution I can think of is to return a DummyObject instead of 0. The dummy object will resolve all properties (so they don't throw errors in cases like {{ test.property.evenDeeperProperty }}) and can be coerced to any type (so they don't throw errors in cases like {{ test.numProperty + 100 }}).

@mattcoley mattcoley requested a review from boulter June 12, 2019 19:33
@mattcoley mattcoley merged commit 3560246 into master Jun 13, 2019
@mattcoley mattcoley deleted the dummy-object branch June 13, 2019 13:31
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

Successfully merging this pull request may close these issues.

2 participants