Bug 2419719 - TypeError: 'NoneType' object is not callable in magic.close()
Summary: TypeError: 'NoneType' object is not callable in magic.close()
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: file
Version: rawhide
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Vincent Mihalkovič
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2025-12-06 20:40 UTC by Bryn M. Reeves
Modified: 2026-03-09 15:00 UTC (History)
2 users (show)

Fixed In Version: file-5.47-1.fc45
Clone Of:
Environment:
Last Closed: 2026-03-02 11:20:54 UTC
Type: ---
Embargoed:
lzaoral: mirror+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker FC-2934 0 None None None 2026-01-12 13:27:43 UTC

Description Bryn M. Reeves 2025-12-06 20:40:29 UTC
Description of problem:

TypeError on exit from python process that used magic.

Version-Release number of selected component (if applicable):
python3-file-magic-5.46-8.fc44.noarch
python3-file-magic-5.46-3.fc42.noarch

I'm seeing a 100% reproducible TypeError when exiting a Python process that has used magic:

  Exception ignored while calling deallocator <function MagicDetect.__del__ at 0x7f44719aef00>:
  Traceback (most recent call last):
    File "/usr/lib/python3.14/site-packages/magic.py", line 308, in __del__
    File "/usr/lib/python3.14/site-packages/magic.py", line 135, in close
  TypeError: 'NoneType' object is not callable

This is happening via:

 74 _close = _libraries['magic'].magic_close
...
131     def close(self):
132         """
133         Closes the magic database and deallocates any resources used.
134         """
135         _close(self._magic_t)
...
285 class MagicDetect(object):
...
306     def __del__(self):
307         if self.mime_magic is not None:
308             self.mime_magic.close()
309         if self.none_magic is not None:
310             self.none_magic.close()

It goes away if I patch magic.py:

--- magic.py.orig	2025-12-06 15:18:29.841776375 -0500
+++ magic.py	2025-12-06 15:18:37.777000000 -0500
@@ -132,7 +132,8 @@ class Magic(object):
         """
         Closes the magic database and deallocates any resources used.
         """
-        _close(self._magic_t)
+        if _close:
+            _close(self._magic_t)
 
     @staticmethod
     def __tostr(s):

But this seems like it's just working around the problem.

Affects rawhide and f42 but does not appear in python3-file-magic-5.39-16.el9.noarch in c9s/rhel9. Haven't tested other Fedora releases yet.

Reproducible: Always

Steps to Reproduce:
It's easiest to reproduce in the Python shell:

# python3
Python 3.14.0 (main, Oct 17 2025, 00:00:00) [GCC 15.2.1 20250924 (Red Hat 15.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
>>> magic.detect_from_filename("/etc/os-release")
FileMagic(mime_type='inode/symlink', encoding='binary', name='symbolic link to ../usr/lib/os-release')
>>> 
Exception ignored while calling deallocator <function MagicDetect.__del__ at 0x7f4b3fb9af00>:
Traceback (most recent call last):
  File "/usr/lib/python3.14/site-packages/magic.py", line 308, in __del__
  File "/usr/lib/python3.14/site-packages/magic.py", line 135, in close
TypeError: 'NoneType' object is not callable
Actual Results:
Exception ignored while calling deallocator <function MagicDetect.__del__ at 0x7f4b3fb9af00>:
Traceback (most recent call last):
  File "/usr/lib/python3.14/site-packages/magic.py", line 308, in __del__
  File "/usr/lib/python3.14/site-packages/magic.py", line 135, in close
TypeError: 'NoneType' object is not callable

Expected Results:
No exception output.

Additional Information:
I see this with some scripts using "#!/usr/bin/python3" but not others - it's not clear why yet. A trivial:
  # cat /tmp/magictest.py
  #!/usr/bin/python3
  import magic
  print(magic.detect_from_filename('/etc/os-release'))

Does not show the error:

  # /tmp/magictest.py
  FileMagic(mime_type='inode/symlink', encoding='binary', name='symbolic link to ../usr/lib/os-release')
  #

But a script that uses packages that indirectly import magic does:

  # /tmp/diffest.py before-upgrade > /dev/null
  INFO - Discovering snapshot set mounts under '/run/snapm/mounts'
  INFO - Found snapshot set mount at '/run/snapm/mounts/before-upgrade' (mounted=True)
  INFO - Found 1 snapshot set mounts
  INFO - Gathering paths to scan from '/run/snapm/mounts/before-upgrade/etc'
  INFO - Gathering paths to scan from '/etc'
  Exception ignored in: <function MagicDetect.__del__ at 0x7f6db98ffa60>
  Traceback (most recent call last):
    File "/usr/lib/python3.13/site-packages/magic.py", line 308, in __del__
    File "/usr/lib/python3.13/site-packages/magic.py", line 135, in close
  TypeError: 'NoneType' object is not callable

Comment 1 Bryn M. Reeves 2025-12-06 20:45:33 UTC
Forgot to add f43 is also affected (python3-file-magic-5.46-8.fc43.noarch).

Comment 2 Vincent Mihalkovič 2026-03-02 11:20:54 UTC
Resolved via: https://src.fedoraproject.org/rpms/file/pull-request/39

Thank you for the report, I did a follow-up on your fix and upstreamed the change!

Comment 3 Bryn M. Reeves 2026-03-02 12:12:18 UTC
Awesome, thanks! I followed the dist-git PR. I'm out this afternoon but I will test when I can-patches LGTM!

Comment 4 Fedora Update System 2026-03-09 13:46:14 UTC
FEDORA-2026-a740b8672f (file-5.47-1.fc45) has been submitted as an update to Fedora 45.
https://bodhi.fedoraproject.org/updates/FEDORA-2026-a740b8672f

Comment 5 Fedora Update System 2026-03-09 15:00:47 UTC
FEDORA-2026-a740b8672f (file-5.47-1.fc45) has been pushed to the Fedora 45 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.