Blob Blame History Raw
From ca06d200d738fd6b23cb05b9776c9fd29288665f Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Wed, 25 Nov 2020 13:00:22 +0100
Subject: [PATCH 1/2] Change behaviour of Package().from_repo

The change makes a difference between private attribute _from_repo and
API attribute. _from_repo is required for `dnf info` and we have to keep
it, but for API the magic handling behind could be confusing.
---
 dnf/package.py      | 8 +++++++-
 doc/api_package.rst | 5 ++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/dnf/package.py b/dnf/package.py
index f647df6bff..28ca5ef760 100644
--- a/dnf/package.py
+++ b/dnf/package.py
@@ -73,6 +73,12 @@ def _from_system(self):
 
     @property
     def _from_repo(self):
+        """
+        For installed packages returns id of repository from which the package was installed
+        prefixed with '@' (if such information is available in the history database). Otherwise
+        returns id of repository the package belongs to (@System for installed packages of unknown
+        origin)
+        """
         pkgrepo = None
         if self._from_system:
             pkgrepo = self.base.history.repo(self)
@@ -83,7 +89,7 @@ def _from_repo(self):
     @property
     def from_repo(self):
         # :api
-        return self._from_repo
+        return self.base.history.repo(self)
 
     @property
     def _header(self):
diff --git a/doc/api_package.rst b/doc/api_package.rst
index a78897babe..634f504ca6 100644
--- a/doc/api_package.rst
+++ b/doc/api_package.rst
@@ -76,9 +76,8 @@
 
   .. attribute:: from_repo
 
-    For installed packages returns id of repository from which the package was installed prefixed
-    with '@' (if such information is available in the history database). Otherwise returns id of
-    repository the package belongs to (@System for installed packages of unknown origin) (string).
+    For installed packages returns id of repository from which the package was installed if such
+    information is available in the history database. Otherwise returns an empty string (string).
 
   .. attribute:: group
 

From 895e61a1281db753dd28f01c20816e83c5316cdd Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Thu, 26 Nov 2020 10:02:08 +0100
Subject: [PATCH 2/2] fixup! Change behaviour of Package().from_repo

---
 dnf/package.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/dnf/package.py b/dnf/package.py
index 28ca5ef760..baef04fa5b 100644
--- a/dnf/package.py
+++ b/dnf/package.py
@@ -89,7 +89,9 @@ def _from_repo(self):
     @property
     def from_repo(self):
         # :api
-        return self.base.history.repo(self)
+        if self._from_system:
+            return self.base.history.repo(self)
+        return ""
 
     @property
     def _header(self):