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

Table aggregation limit and suffix settings not respected #1144

Open
grantfitzsimmons opened this issue Jan 18, 2022 · 6 comments
Open

Table aggregation limit and suffix settings not respected #1144

grantfitzsimmons opened this issue Jan 18, 2022 · 6 comments
Assignees
Labels
1 - Bug Incorrect behavior of the product 2 - Forms Issues that are related to the form system 2 - Schema Config Issues that are related to the Schema Config tool

Comments

@grantfitzsimmons
Copy link
Member

Describe the bug
The schema configuration's customized aggregation does not effect how the report runner works.

To Reproduce
Steps to reproduce the behavior:

  1. Customize the schema to display some limit:

Specify_0omQHHpWRE

  1. Print labels using the aggregated output of that field. See error.

Expected behavior
In Specify 6, the schema configuration is respected when running a report. In Specify 7, reports ignore this configuration but should do the same.

Screenshots
D4bss8pAhj

Desktop (please complete the following information):

  • OS: Windows 10, macOS
  • Browser: Edge
  • Specify 7 Version: 7.6.1 & Edge

Reported By
Grant on behalf of LSUMZ

@grantfitzsimmons grantfitzsimmons added 1 - Bug Incorrect behavior of the product pri:unknown labels Jan 18, 2022
@benanhalt benanhalt changed the title Schema table aggregation settings not respected on reports & labels Schema table aggregation limit and ending settings not respected on reports & labels Jan 18, 2022
@benanhalt benanhalt changed the title Schema table aggregation limit and ending settings not respected on reports & labels Schema table aggregation limit and ending settings not respected. Jan 18, 2022
@benanhalt
Copy link
Contributor

Specify 7 currently ignores the the count and ending settings of aggregators. This applies to queries as well.

@benanhalt
Copy link
Contributor

Because Specify 7 does all the formatting and aggregation at the database level, tt would be best to figure out how to express the logic in SQL. MariaDB supports a limit clause in the GROUP_CONCAT function which fits the bill nicely:

> select concat(group_concat(lastname separator '; ' limit 3), if(count(*) > 3, '...', '')) as agents from agent where firstname = 'James'\G
*************************** 1. row ***************************
agents: Smith; Triplett; Deacon...

> select concat(group_concat(lastname separator '; ' limit 3), if(count(*) > 3, '...', '')) as agents from agent where firstname = 'Bill'\G
*************************** 1. row ***************************
agents: Cole; Ludt

To support it in MySQL it would probably be necessary to use SUBSTRING_INDEX on the separator after suppressing any occurrence of the separator in the values using REPLACE.

I'm thinking it wouldn't be too hard to add either of these approaches, but the MariaDB one is better. It might be possible to check if the server is MySQL or MariaDB and generate the corresponding SQL.

The relevant code is at

aggregated = blank_nulls(group_concat(formatted, separator, *order_by))
and
def _group_concat_mysql(element, compiler, **kwargs):
expr = compiler.process(element.clauses.clauses[0])
def process_clause(idx):
return compiler.process(element.clauses.clauses[idx])
separator = process_clause(1) if len(element.clauses) > 1 else None
order_by = process_clause(2) if len(element.clauses) > 2 else None
inner = expr
if order_by is not None:
inner += " ORDER BY %s" % order_by
if separator is not None:
inner += " SEPARATOR %s" % separator
return 'GROUP_CONCAT(%s)' % inner

@benanhalt
Copy link
Contributor

>>> from django.db import connection
>>> connection.mysql_is_mariadb
True
>>> 

@maxpatiiuk
Copy link
Member

#2796 adds front-end support for this. Back-end support is still pending

@grantfitzsimmons grantfitzsimmons moved this to 📋 Backlog in Back-End Backlog Mar 9, 2023
@maxpatiiuk maxpatiiuk assigned acwhite211 and unassigned benanhalt Mar 18, 2023
@grantfitzsimmons grantfitzsimmons added 2 - Forms Issues that are related to the form system and removed Unsorted labels Jul 2, 2023
@grantfitzsimmons grantfitzsimmons added the 2 - Schema Config Issues that are related to the Schema Config tool label Aug 7, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Front-End Backlog Aug 7, 2023
@grantfitzsimmons grantfitzsimmons moved this from 📋 Backlog to ✅ Done in Front-End Backlog Aug 7, 2023
@grantfitzsimmons grantfitzsimmons added this to the Grant's issue list milestone Aug 7, 2023
@grantfitzsimmons grantfitzsimmons changed the title Schema table aggregation limit and ending settings not respected. Table aggregation limit and suffix settings not respected Jun 11, 2024
@grantfitzsimmons
Copy link
Member Author

grantfitzsimmons commented Jun 11, 2024

See custom format:
image
image

See newly defined report with the specified format:
image

Relevant XML in the DataObjFormatters file:

<aggregator name="Determination" title="Determination" class="edu.ku.brc.specify.datamodel.Determination" default="true" separator=" | " ending="..." count="3" format="Determination" orderfieldname="isCurrent"/>

2024-06-11 still not having any luck on v7.9.5

@realVinayak realVinayak self-assigned this Jun 11, 2024
@emenslin
Copy link
Collaborator

Can recreate in edge (7.9.6)

@realVinayak realVinayak removed their assignment Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - Bug Incorrect behavior of the product 2 - Forms Issues that are related to the form system 2 - Schema Config Issues that are related to the Schema Config tool
Projects
Status: 📋 Backlog
Status: Done
Development

No branches or pull requests

6 participants