devel/py-pygit2: AttributeError: ‘_pygit2.Commit’ object has no attribute ‘oid’. Did you mean: ‘id’?

Today I updated the test ingress node of FreshPorts. Not long after, I was told by Nagios monitoring:

Notification Type: PROBLEM

Service: FreshPorts dev-vs-test
Host: webserver
Address: webserver.int.unixathome.org
State: WARNING

Date/Time: Sat Oct 19 13:22:51 UTC 2024

Additional Info:

--- /tmp/url-compare.gRydZE2024-10-19 13:22:48.300556000 +0000

I had a similar message comparing test to stage.

Soon after, I saw this error in the logs:

Oct 19 12:18:04 test-ingress01 dvl[12403]: FATAL eror with git-to-freshports-xml.py result: 1 - check git-delta.sh logs for more detail

Looking farther, I found this:

2024.10.19 12:18:03 git-delta.sh The commits found are:
2024.10.19 12:18:03 git-delta.sh 0682711dee4631234d7cc197af3e92acb936d6da
2024.10.19 12:18:03 git-delta.sh /usr/local/libexec/freshports/git-to-freshports-xml.py --repo ports --path /var/db/ingress/repos/ports --branch main --commit-range 57537ad6cea08e3d16cd67b1280b5723be42d08a..0682711dee4631234d7cc197af3e92acb936d6da --spooling /var/db/ingress/message-queues/spooling --output /var/db/ingress/message-queues/incoming
Traceback (most recent call last):
  File "/usr/local/libexec/freshports/git-to-freshports-xml.py", line 267, in <module>
    main()
  File "/usr/local/libexec/freshports/git-to-freshports-xml.py", line 161, in main
    commits = commit_range(repo, config['commit_range'])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/libexec/freshports/git-to-freshports-xml.py", line 125, in commit_range
    walker = repo.walk(end_commit.oid)
                       ^^^^^^^^^^^^^^
AttributeError: '_pygit2.Commit' object has no attribute 'oid'. Did you mean: 'id'?
2024.10.19 12:18:04 git-delta.sh /usr/local/libexec/freshports/git-to-freshports-xml.py result: 1
2024.10.19 12:18:04 git-delta.sh Now processing repo: src ---------------
2024.10.19 12:18:04 git-delta.sh REPODIR='/var/db/ingress/repos/src' exists
2024.10.19 12:18:04 git-delta.sh Repodir is /var/db/ingress/repos/src
2024.10.19 12:18:04 git-delta.sh Running: /usr/local/bin/git fetch:
2024.10.19 12:18:04 git-delta.sh fetch completed.

Tracking it down

It seems that oid has gone away with this upgrade:

Oct 19 11:47:00 test-ingress01 pkg[61274]: py311-pygit2 upgraded: 1.14.1 -> 1.15.1 

Visiting devel/py-pygit2 (the irony of using FreshPorts to debug FreshPorts is not lost on me) I found the home page and the Github repo. Searching the issues for oid, I found issue 1316

Fixing it

I found a list of breaking changes, fixed my code, ran it, fixed more code, ran it, all good.

This is the diff I had on test:

[14:41 test-ingress01 dvl /usr/local/libexec/freshports] % diff -ruN git-to-freshports-xml.py.orig git-to-freshports-xml.py
--- git-to-freshports-xml.py.orig	2024-10-19 14:13:45.235491000 +0000
+++ git-to-freshports-xml.py	2024-10-19 14:40:20.000000000 +0000
@@ -122,7 +122,7 @@
     start_commit = repo.revparse_single(start_commit_ref)
     end_commit   = repo.revparse_single(end_commit_ref)
 
-    walker = repo.walk(end_commit.oid)
+    walker = repo.walk(end_commit.id)
     walker.simplify_first_parent()  # Avoid wandering off to merged branches. Same as 'git log --first-parent'
 
     result = []
@@ -171,7 +171,7 @@
 
     for order_number, commit in enumerate(commits):
         commit: pygit2.Commit
-        log.info(f"Processing commit '{commit.hex} {commit.message.splitlines()[0]}'")
+        log.info(f"Processing commit '{str(commit.id)} {commit.message.splitlines()[0]}'")
         root = ET.Element('UPDATES', Version=FORMAT_VERSION, Source='git')
         update = ET.SubElement(root, 'UPDATE')
 
@@ -193,11 +193,11 @@
             commit_branches = list(repo.branches.remote.with_commit(commit))
             commit_branches_num = len(commit_branches)
             if commit_branches_num == 0:
-                log.error(f"Unable to get branch name for commit {commit.hex}. "
+                log.error(f"Unable to get branch name for commit {str(commit.id)}. "
                           f"Make sure that the local tracking branch exists for the remote branch.")
                 continue
             elif commit_branches_num > 1:
-                log.warning(f"Ambiguity in getting branch name for commit {commit.hex}. Got branches: {commit_branches}."
+                log.warning(f"Ambiguity in getting branch name for commit {str(commit.id)}. Got branches: {commit_branches}."
                             f"Using the first one: {commit_branches[0]}")
             ET.SubElement(update, 'OS', Repo=config['repo'], Id=config['os'], Branch=commit_branches[0])
 
@@ -214,7 +214,7 @@
         ET.SubElement(people, 'AUTHOR',    AuthorName=f"{commit.author.name}",       AuthorEmail=f"{commit.author.email}")
 
         log.debug("Writing commit hash")
-        ET.SubElement(update, 'COMMIT', Hash=commit.hex, HashShort=commit.short_id,
+        ET.SubElement(update, 'COMMIT', Hash=str(commit.id), HashShort=commit.short_id,
                       Subject=commit.message.splitlines()[0], EncodingLoses="false", Repository=config['repo'])
 
         files = ET.SubElement(update, 'FILES')
@@ -244,7 +244,7 @@
 
         file_name = (f"{commit_datetime.year}.{commit_datetime.month:02d}.{commit_datetime.day:02d}."
                      f"{commit_datetime.hour:02d}.{commit_datetime.minute:02d}.{commit_datetime.second:02d}."
-                     f"{order_number:06d}.{commit.hex}.xml")
+                     f"{order_number:06d}.{str(commit.id)}.xml")
         file_mode = 'wb' if config['force'] else 'xb'
         log.debug("Dumping XML")
         try:
[14:41 test-ingress01 dvl /usr/local/libexec/freshports] % 

That code was copied over to my working FreshPorts node, and committed here.

Thanks

My thanks for Serhii (Sergey) Kozlov for their work on the original code.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Comment

Scroll to Top