工作代码,新错误:XXX必须通过子句出现在组中或用于聚合函数

发布于 2025-01-23 10:29:38 字数 2445 浏览 0 评论 0原文

我需要一些帮助。

最近,我们必须更新应用程序的烧瓶库才能部署它,但是现在我们正在处理以前没有任何问题的函数中的错误:

backend_1      | 2022-04-19 11:41:41,814 ERROR    Internal Server Error: /api/v1/booking/quote/agent-quotes-list/
backend_1      | Traceback (most recent call last):
backend_1      |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
backend_1      |     return self.cursor.execute(sql, params)
backend_1      | psycopg2.errors.GroupingError: column "v0.date_created" must appear in the GROUP BY clause or be used in an aggregate function
backend_1      | LINE 1: ...OUP BY V0."id" HAVING COUNT(V2."id") < 5 ORDER BY V0."date_created"

功能是这样的:

@action(methods=['get'], detail=False, url_path='agent-quotes-list')
def get_agent_quotes_list(self, request, *args, **kwargs):
    user = request.user
    company = user.get_company()

    queryset = self.get_queryset().filter(is_active=True, company__disabled=False) \
        .exclude(statuses__status=Status.REJECTED,
                 statuses__company=company)
    submitted_air = queryset.filter(shipping_mode__shipping_type__title='air',
                                    statuses__status=Status.SUBMITTED,
                                    freight_rates__company=company)
    submitted_sea = queryset.filter(shipping_mode__shipping_type__title='sea',
                                    statuses__status=Status.SUBMITTED,
                                    freight_rates__company=company)

    number_of_bids = ClientPlatformSetting.load().number_of_bids
    queryset = queryset.annotate(bids_count=Count('statuses')).filter(bids_count__lt=number_of_bids)

    not_submitted_air = queryset.filter(shipping_mode__shipping_type__title='air').exclude(
        statuses__status=Status.SUBMITTED,
        freight_rates__company=company
    ).order_by('date_created')[:10]
    not_submitted_sea = queryset.filter(shipping_mode__shipping_type__title='sea').exclude(
        statuses__status=Status.SUBMITTED,
        freight_rates__company=company
    ).order_by('date_created')[:10]

    queryset = (submitted_air | submitted_sea | not_submitted_air | not_submitted_sea).order_by('date_created')
    queryset = self.filter_queryset(queryset)
    serializer = self.get_serializer(queryset, many=True)
    return Response(serializer.data)

BTW,我非常非常这一切都是新的,请以任何不一致的意义,因为我不是开发人员。

我们正在使用Postgres 13.4用于DB。

I need some help with something.

Recently we had to update the Flask library of an app to be able to deploy it, but now we're dealing an error in a function that didn't have any issues before:

backend_1      | 2022-04-19 11:41:41,814 ERROR    Internal Server Error: /api/v1/booking/quote/agent-quotes-list/
backend_1      | Traceback (most recent call last):
backend_1      |   File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
backend_1      |     return self.cursor.execute(sql, params)
backend_1      | psycopg2.errors.GroupingError: column "v0.date_created" must appear in the GROUP BY clause or be used in an aggregate function
backend_1      | LINE 1: ...OUP BY V0."id" HAVING COUNT(V2."id") < 5 ORDER BY V0."date_created"

and the function goes like this:

@action(methods=['get'], detail=False, url_path='agent-quotes-list')
def get_agent_quotes_list(self, request, *args, **kwargs):
    user = request.user
    company = user.get_company()

    queryset = self.get_queryset().filter(is_active=True, company__disabled=False) \
        .exclude(statuses__status=Status.REJECTED,
                 statuses__company=company)
    submitted_air = queryset.filter(shipping_mode__shipping_type__title='air',
                                    statuses__status=Status.SUBMITTED,
                                    freight_rates__company=company)
    submitted_sea = queryset.filter(shipping_mode__shipping_type__title='sea',
                                    statuses__status=Status.SUBMITTED,
                                    freight_rates__company=company)

    number_of_bids = ClientPlatformSetting.load().number_of_bids
    queryset = queryset.annotate(bids_count=Count('statuses')).filter(bids_count__lt=number_of_bids)

    not_submitted_air = queryset.filter(shipping_mode__shipping_type__title='air').exclude(
        statuses__status=Status.SUBMITTED,
        freight_rates__company=company
    ).order_by('date_created')[:10]
    not_submitted_sea = queryset.filter(shipping_mode__shipping_type__title='sea').exclude(
        statuses__status=Status.SUBMITTED,
        freight_rates__company=company
    ).order_by('date_created')[:10]

    queryset = (submitted_air | submitted_sea | not_submitted_air | not_submitted_sea).order_by('date_created')
    queryset = self.filter_queryset(queryset)
    serializer = self.get_serializer(queryset, many=True)
    return Response(serializer.data)

BTW I'm very new to all this so please, take any inconsistency as ignorance in the subject because I'm not a developer.

We're using Postgres 13.4 for the db.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文