Skip to content

dnf5daemon: Filter package attributes for removed packages - #3076

Open
LUX-ETVERITAS wants to merge 2 commits into
rpm-software-management:mainfrom
LUX-ETVERITAS:fix/history-removed-package-attrs
Open

LUX-ETVERITAS wants to merge 2 commits into
rpm-software-management:mainfrom
LUX-ETVERITAS:fix/history-removed-package-attrs

Conversation

@LUX-ETVERITAS

@LUX-ETVERITAS LUX-ETVERITAS commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Honor package_attrs in History.recent_changes for removed packages. Return the requested subset of name, arch, and evr, and always include transaction_time.

Use the same attribute lookup as package_to_map so that an unknown name raises the same D-Bus error. Recognized attributes unavailable in transaction history, such as summary, are still omitted. This preserves the default response.

Added regression scenarios for attribute filtering and rejection of an unknown name. Tested the rebuilt daemon on a private D-Bus with default attributes, ['name'], [], ['summary', 'evr'], and ['name', 'unknown']. Confirmed that the previous revision silently accepted the unknown name.

Fixes #2536

@LUX-ETVERITAS
LUX-ETVERITAS requested a review from a team as a code owner November 29, 2026 03:39
@LUX-ETVERITAS
LUX-ETVERITAS requested review from kontura and removed request for a team November 29, 2026 03:39
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Filter removed-package attributes in History.recent_changes

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 10-20 Minutes


AI Description

• Honor package_attrs for removed packages while preserving the default response and mandatory
 transaction_time.
• Document available removed-package fields and test selected, empty, and unsupported attribute
 requests.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed XML contract and History::recent_changes implementation jointly define one bounded API behavior: selecting fields in the installed, upgraded, downgraded, and removed package results.
  • The package conversion helper is an implementation hop within this integration, not an independent capability.
Sources

dnf5daemon-server/services/history/history.cpp[147-150]

    auto pkg_attrs = dnfdaemon::key_value_map_get<std::vector<std::string>>(
        options, "package_attrs", std::vector<std::string>{"name", "summary", "evr", "arch"});
    const std::vector<std::string> default_removed_attrs{"name", "arch", "evr"};
    const auto & removed_attrs = options.contains("package_attrs") ? pkg_attrs : default_removed_attrs;

dnf5daemon-server/services/history/history.cpp[109-127]

dnfdaemon::KeyValueMap history_package_to_map(
    const libdnf5::transaction::Package & trans_pkg, const std::vector<std::string> & attrs) {
    dnfdaemon::KeyValueMap dbus_package;
    for (const auto & attr : attrs) {
        switch (package_attribute_from_string(attr)) {
            case PackageAttribute::name:
                dbus_package.emplace(attr, trans_pkg.get_name());
                break;
            case PackageAttribute::arch:
                dbus_package.emplace(attr, trans_pkg.get_arch());
                break;
            case PackageAttribute::evr:
                dbus_package.emplace(attr, get_evr(trans_pkg));
                break;
            default:
                throw std::runtime_error(
                    libdnf5::utils::sformat("Package attribute '{}' not supported for removed packages", attr));
        }
    }
Behavioral complexity 🟡 Medium 🧩 Compatibility cases

  • Before: removed packages always emitted name, arch, and evr, while package_attrs controlled other package categories.
  • After: omitted package_attrs uses the removed-package default, while an explicit list is validated against the removed-package subset.
  • New correctness condition: the implementation must distinguish explicit versus omitted options and apply different supported-attribute rules only when a removed package reaches the response; installed, upgraded, and downgraded mapping continues through the existing package serializer.
  • The shared attribute lookup extraction does not itself add a new interaction.
Sources

dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.History.xml[57-59]

        For removed packages, the default attributes are name, arch, and evr.
        If package_attrs is specified and the result includes a removed package,
        requesting any attribute outside this set raises an error.

dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.History.xml[80-84]

            - package_attrs: list of strings, default ["name", "summary", "evr", "arch"] for
                installed, upgraded, and downgraded packages, ["name", "arch", "evr"] for removed packages
                List of package attributes that are returned for each changed
                package. For installed, upgraded, and downgraded packages, supported
                attributes are the same as in the list() method of the Rpm interface.

dnf5daemon-server/services/history/history.cpp[109-127]

dnfdaemon::KeyValueMap history_package_to_map(
    const libdnf5::transaction::Package & trans_pkg, const std::vector<std::string> & attrs) {
    dnfdaemon::KeyValueMap dbus_package;
    for (const auto & attr : attrs) {
        switch (package_attribute_from_string(attr)) {
            case PackageAttribute::name:
                dbus_package.emplace(attr, trans_pkg.get_name());
                break;
            case PackageAttribute::arch:
                dbus_package.emplace(attr, trans_pkg.get_arch());
                break;
            case PackageAttribute::evr:
                dbus_package.emplace(attr, get_evr(trans_pkg));
                break;
            default:
                throw std::runtime_error(
                    libdnf5::utils::sformat("Package attribute '{}' not supported for removed packages", attr));
        }
    }

dnf5daemon-server/services/history/history.cpp[147-150]

    auto pkg_attrs = dnfdaemon::key_value_map_get<std::vector<std::string>>(
        options, "package_attrs", std::vector<std::string>{"name", "summary", "evr", "arch"});
    const std::vector<std::string> default_removed_attrs{"name", "arch", "evr"};
    const auto & removed_attrs = options.contains("package_attrs") ? pkg_attrs : default_removed_attrs;
Potential damage 🟡 Medium 🩹 Recoverable

  • If this capability regresses, a recent_changes call can return incorrect removed-package fields or fail when validating requested attributes.
  • The supported path has no persistent-state or external side effect; retrying with supported attributes or reverting the code restores service behavior.
  • A caller can retry with name, arch, and evr for removed packages.
  • A code revert restores the prior implementation, and no stored history data requires repair.
Sources

dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.History.xml[57-59]

        For removed packages, the default attributes are name, arch, and evr.
        If package_attrs is specified and the result includes a removed package,
        requesting any attribute outside this set raises an error.

dnf5daemon-server/services/history/history.cpp[109-127]

dnfdaemon::KeyValueMap history_package_to_map(
    const libdnf5::transaction::Package & trans_pkg, const std::vector<std::string> & attrs) {
    dnfdaemon::KeyValueMap dbus_package;
    for (const auto & attr : attrs) {
        switch (package_attribute_from_string(attr)) {
            case PackageAttribute::name:
                dbus_package.emplace(attr, trans_pkg.get_name());
                break;
            case PackageAttribute::arch:
                dbus_package.emplace(attr, trans_pkg.get_arch());
                break;
            case PackageAttribute::evr:
                dbus_package.emplace(attr, get_evr(trans_pkg));
                break;
            default:
                throw std::runtime_error(
                    libdnf5::utils::sformat("Package attribute '{}' not supported for removed packages", attr));
        }
    }
Assessed commit 1532ee4
Diagram

graph TD
  caller["D-Bus caller"] --> method["recent_changes"] --> record["History record"] --> filter{"Requested and available?"}
  filter -->|include| mapped["Removed map"] --> stamp["Add transaction time"] --> result["D-Bus response"]
  filter -->|skip| mapped
Loading
High-Level Assessment

Keep the focused history-package conversion: removed packages have only transaction-history fields, so using the installed-package converter would require unavailable package data. The existing default attributes and separate mandatory timestamp remain intact.

Files changed (3) +32 / -7

Bug fix (1) +12 / -5
history.cppFilter removed-package fields by package_attrs +12/-5

Filter removed-package fields by package_attrs

• Builds removed-package maps from requested history-supported fields instead of always including name, arch, and evr. recent_changes still adds transaction_time for every removed entry, including when no attributes are requested.

dnf5daemon-server/services/history/history.cpp

Tests (1) +18 / -0
history.featureCover removed-package attribute filtering +18/-0

Cover removed-package attribute filtering

• Adds a D-Bus regression scenario for name-only, empty, and unsupported-plus-evr requests. It verifies the returned keys and transaction_time.

integration-tests/dnf-behave-tests/dnf/api/dbus/history.feature

Documentation (1) +2 / -2
org.rpm.dnf.v0.History.xmlClarify attribute selection for removed packages +2/-2

Clarify attribute selection for removed packages

• Documents that removed packages can provide name, arch, and evr, but return only those selected by package_attrs.

dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.History.xml

m-blaha
m-blaha previously approved these changes Dec 1, 2026

@m-blaha m-blaha left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Comment on lines +111 to +119
for (const auto & attr : attrs) {
if (attr == "name") {
dbus_package.emplace(attr, trans_pkg.get_name());
} else if (attr == "arch") {
dbus_package.emplace(attr, trans_pkg.get_arch());
} else if (attr == "evr") {
dbus_package.emplace(attr, get_evr(trans_pkg));
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When an unsupported attribute is passed I believe it silently skips it.
The regular package_to_map throws an exception in such a case, could we add a similar check also here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed on 59aff22

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok, now its limited to package_attributes but this history_package_to_map supports only a subset (name, arch and evr). If you pass for example url here is will still be silently ignored.

@LUX-ETVERITAS

Copy link
Copy Markdown
Contributor Author

/packit retest-failed

@LUX-ETVERITAS

Copy link
Copy Markdown
Contributor Author

The Rawhide dnf5-tests job fails during argument parsing. The test harness passes --setopt=module_platform_id=platform:f29, which the tested dnf5 rejects with Option "module_platform_id" not found. This also affects unrelated CLI tests, including alias handling. The Rawhide dnf5daemon-tests job covering the D-Bus history change passed. Testing Farm log

Honor package_attrs in History.recent_changes when returning removed packages. Keep transaction_time present for every entry, including requests with an empty attribute list.

Fixes rpm-software-management#2536

Assisted-by: Codex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dnf5daemon: org.rpm.dnf.v0.History does not filter package_attrs for removed packages

3 participants