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
Account for null XForm instances in service_usage endpoint #4635
Conversation
kpi/serializers/v2/service_usage.py
Outdated
Asset.objects.only( | ||
Asset.all_objects.only( | ||
'pk', | ||
'uid', | ||
'_deployment_data', | ||
'owner_id', | ||
'name', | ||
) | ||
.select_related('owner') | ||
.exclude(_deployment_data=None) | ||
.filter( | ||
owner__in=self._users, | ||
asset_type=ASSET_TYPE_SURVEY, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user_assets
seems to be used no where else than to be used to init asset_list
I would probably get rid of user_assets
and assign directly asset_list
with the results of queryset with values_list()
Moreover, the query could simplified with the new date_deployed
field. Only assets of type 'survey'
are deployed. We just need to check whether the value of the field is not null to get all deployed projects.
So what about this?
asset_list = list(
Asset.all_objects.values_list('uid', flat=True).filter(
owner__in=self._users,
date_deployed__isnull=False,
)
)
xforms = KobocatXForm.objects.only('bytes_sum', 'id', 'kpi_asset_uid').filter(
kpi_asset_uid__in=asset_list,
)
Checklist
Description
Fix
/api/v2/service_usage/
calculating NLP and submission counts incorrectly.Notes
Deleting a form with submissions currently causes the submission counter to decrement. The endpoint previously did handle this correctly, but it was refactored as part of
feature/usage-limits
, which introduced this regression. See kobocat#895 for additional background.Related issues
Depends on kobotoolbox/kobocat#895
See issue on Release 2.023.37 QA board.