The problem is that I assumed that in Application.load_usage_limits_affected_by all the metrics passed were already validated, but that was a mistake because the listener does not validate the metrics until it runs the Limits validator, which happens later in the process.
We didn't caught this because we didn't have tests that used both no_body=true, and reported more than 1 metric and at least an invalid one. I have included tests for that in this PR.
In the future, maybe we should make the metrics validation more explicit as a separate test in the transactor rather than have it hidden in the Limits validator.
This PR fixes a bug introduced in #221
The problem is that I assumed that in
Application.load_usage_limits_affected_by
all the metrics passed were already validated, but that was a mistake because the listener does not validate the metrics until it runs theLimits
validator, which happens later in the process.More specificaly, when a metric does not exist,
Metric.load_id
returns nil and then, the sort here crashes: https://github.com/3scale/apisonator/blob/e965a2228c331c21b159925d16888a5f473ef26c/lib/3scale/backend/application.rb#L241We didn't caught this because we didn't have tests that used both
no_body=true
, and reported more than 1 metric and at least an invalid one. I have included tests for that in this PR.In the future, maybe we should make the metrics validation more explicit as a separate test in the transactor rather than have it hidden in the
Limits
validator.