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

Filter upgrades to support kw params #531

Merged
merged 7 commits into from
Nov 16, 2020

Conversation

michaelpro1
Copy link
Contributor

This change includes the following:

  • Upgrades to filters with >1 params that have 100% code coverage
  • There are some fixes to Jinjavadoc as they didn't match unit tests

@boulter This is following up on the AbstractFilter #523 , these are draft changes so let me know what you think of these changes and whether you'd prefer split PRs too

Jinjavadoc alignment with tests includes:

  • DateTimeFormatFilter
  • JoinFilter
  • various number => int changes where filter actually required an integer - the conversion is done in AbstractFilter

…. Null parameter value is treated as missing
join filter: `attr` renamed to `attribute` matching unit test
datetimeformat: fix function jinjavadoc and param defaults
Copy link
Contributor

@boulter boulter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. It seems to clean up a lot of code.

String format = (String) parsedArgs.get(FORMAT_PARAM);
String timezone = (String) parsedArgs.get(TIMEZONE_PARAM);
String locale = (String) parsedArgs.get(LOCALE_PARAM);
if (format == null && timezone == null && locale == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must all of these be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could probably fix up the Functions code, but currently it errors out on zone being null. Let me know if you are happy for me to change it

@@ -40,19 +41,29 @@
)
}
)
public class DateTimeFormatFilter implements Filter {
public class DateTimeFormatFilter extends AbstractFilter implements Filter {
public static final String FORMAT_PARAM = "format";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really appreciate the static constants!

try {
length = Integer.parseInt(Objects.toString(args[0]));
} catch (Exception e) {
ENGINE_LOG.warn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, this removes a lot of code! Can you ensure that this is still covered in the unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see your point, it ignores parsing errors. Given that we are using defaultValue now did you want to keep parse-and-ignore-error functionality or rely on correct user input/sensible default value?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just confirm that it still validates the value but we don't need to log a warning. It's pretty useless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the last commits, I've added a default on error. Additionally I've fixed up the number parsing as NumberUtils seems to default to 0 if not parsed.

@boulter boulter merged commit 26d72b3 into HubSpot:master Nov 16, 2020
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