mirror of
https://gitlab.com/bramw/baserow.git
synced 2025-04-15 09:34:13 +00:00
Fix iCal feed when the table has select_related fields from enhance_queryset
This commit is contained in:
parent
327e93bbef
commit
547014adf5
3 changed files with 61 additions and 1 deletions
changelog/entries/unreleased/bug
premium/backend
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"type": "bug",
|
||||
"message": "Fix iCal feed when the table has select_related fields from enhance_queryset.",
|
||||
"issue_number": null,
|
||||
"bullet_points": [],
|
||||
"created_at": "2025-02-05"
|
||||
}
|
|
@ -189,7 +189,15 @@ def build_calendar(
|
|||
query_field_names.add(field_name)
|
||||
|
||||
filter_qs = {f"{date_field_name}__isnull": False}
|
||||
qs = qs.filter(**filter_qs).only(*query_field_names)
|
||||
|
||||
# Calculate which fields must be deferred to optimize performance. The idea is
|
||||
# that only the `query_field_names` and `select_related_fields` are kept because
|
||||
# they must be included in the result.
|
||||
model_field_names = {field.name for field in qs.model._meta.get_fields()}
|
||||
select_related_fields = set(qs.query.select_related or [])
|
||||
fields_to_defer = model_field_names - query_field_names - select_related_fields
|
||||
|
||||
qs = qs.filter(**filter_qs).defer(*fields_to_defer)
|
||||
if limit:
|
||||
qs = qs[:limit]
|
||||
|
||||
|
|
|
@ -2412,3 +2412,48 @@ def test_calendar_view_ical_filters(premium_data_fixture, api_client, data_fixtu
|
|||
titles = ["title 4 - "]
|
||||
for tstart, summary in zip(titles, evsummary):
|
||||
assert summary.startswith(tstart)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.view_calendar
|
||||
def test_calendar_view_ical_feed_with_date_and_select_related_field_in_queryset(
|
||||
premium_data_fixture, api_client, data_fixture
|
||||
):
|
||||
user, token = premium_data_fixture.create_user_and_token(
|
||||
has_active_premium_license=True
|
||||
)
|
||||
table, _, _, _, context = setup_interesting_test_table(
|
||||
premium_data_fixture, user=user
|
||||
)
|
||||
date_field = premium_data_fixture.create_date_field(
|
||||
table=table,
|
||||
date_include_time=True,
|
||||
)
|
||||
view_handler = ViewHandler()
|
||||
|
||||
calendar_view: CalendarView = view_handler.create_view(
|
||||
user=user,
|
||||
table=table,
|
||||
type_name="calendar",
|
||||
date_field=date_field,
|
||||
)
|
||||
|
||||
req_patch = partial(
|
||||
api_client.patch, format="json", HTTP_AUTHORIZATION=f"JWT {token}"
|
||||
)
|
||||
resp: Response = req_patch(
|
||||
reverse("api:database:views:item", kwargs={"view_id": calendar_view.id}),
|
||||
{"ical_public": True},
|
||||
)
|
||||
assert resp.status_code == HTTP_200_OK
|
||||
assert resp.data["ical_feed_url"]
|
||||
|
||||
calendar_view.refresh_from_db()
|
||||
req_get = partial(api_client.get, format="json", HTTP_AUTHORIZATION=f"JWT {token}")
|
||||
resp = req_get(
|
||||
reverse(
|
||||
"api:database:views:calendar:calendar_ical_feed",
|
||||
kwargs={"ical_slug": calendar_view.ical_slug},
|
||||
)
|
||||
)
|
||||
assert resp.status_code == HTTP_200_OK
|
||||
|
|
Loading…
Add table
Reference in a new issue