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

Fix: order_by to respect alt #1093

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lektor/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,9 @@ def attachment_filename(self):
def parent(self):
"""The associated record for this attachment."""
return self.pad.get(
self._data["_attachment_for"], persist=self.pad.cache.is_persistent(self)
self._data["_attachment_for"],
alt=self.alt,
persist=self.pad.cache.is_persistent(self)
)

@cached_property
Expand Down Expand Up @@ -1078,7 +1080,7 @@ def get_order_by(self):
"""Returns the order that should be used."""
if self._order_by is not None:
return self._order_by
base_record = self.pad.get(self.path)
base_record = self.pad.get(self.path, alt=self.alt)
Copy link
Contributor

@dairiki dairiki Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like, in this case, we are interested only in base_record.datamodel. The datamodel does not depend on any of the record's .lr files (regardless of alt). Perhaps we should figure out a way that we end up only declaring a dependency on the datamodel .ini file (and and .ini files of datamodels from which it inherits)?

More investigation is probably required to determine whether such an optimization would buy us much (in terms of reducing unnecessary recorded dependencies, and thus reducing unnecessary rebuilds).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this is related to part of PR #1007, where dependency tracking is done in Record.getitem.

Moving dependency tracking to attribute accessors (of both Records and DataModels) rather than recording the dependency upon record traversal would fix this...

Copy link
Contributor Author

@relikd relikd Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this is an issue for all queries with non-default alt. self.pad.get will access the primary alt in that case and record a dependency. I would be happy if, in this case, the datamodel could be accessed without requesting the record and thus avoid a dependency. But for the time being (if an actual fix will take too long) I would appreciate if the alt would be set as a hotfix. This at least prevents unnecessary rebuilds of alternatives if a primary alt page changes.

And dependency tracking via attributes would be superb. There is another issue from 2016 I think where this was proposed. So dependency tracking could finally be applied to individual fields rather than files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And dependency tracking via attributes would be superb. There is another issue from 2016 I think where this was proposed. So dependency tracking could finally be applied to individual fields rather than files.

Yes, that would be nice, but is probably a lot of work, and is not quite what I'm referring to.

My point is that just because a record is fetched (via Pad.get) during the building of an artifact, that does not mean, necessarily, that that artifact depends on that record's source files. It might be better to defer the recording of the dependency until such time as one of the record's fields is accessed, since that does imply a dependency on the source file.

if base_record is not None:
if self._include_attachments and not self._include_pages:
return base_record.datamodel.attachment_config.order_by
Expand Down