astropy / astropy/astroquery

[Bug]: AttributeError on log._set_defaults() in astroquery/logger.py when used as a library dependency

Open
#3,349 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
791
Forks
451
Avg merge
1d 3h
Merged PRs (30d)
4

Description

### [Bug]: AttributeError on log._set_defaults() in astroquery/logger.py when used as a dependency

**Description**

When `astroquery` is used as a dependency in my project [astroquery-cli](https://github.com/inoribea/astroquery-cli), the application fails to start with a fatal `AttributeError` during the import process.

The error originates from `astroquery/logger.py` and suggests that the `log` object is a standard Python `logging.Logger` instance, which lacks the `_set_defaults` method. The expected object type is likely `astropy.logger.AstropyLogger`, which should have this method. This points to a potential issue with how the logger is initialized, possibly due to changes in the `astropy` dependency.

Crucially, this bug appears to be environment-specific. The application crashes in my standard Python environments (v3.11, v3.12, v3.13), but it runs correctly inside a `poetry` virtual environment. This suggests the root cause may be related to dependency resolution or module import order in "non-isolated" environments.

I have confirmed that locally removing the call to `log._set_defaults()` in `astroquery/logger.py` resolves the crash.

**Actual Behavior**

The application crashes on startup when importing `astroquery`. The traceback clearly shows the import chain leading to `astroquery/logger.py`, where the call to `log._set_defaults()` fails:

```text
Traceback (most recent call last):
File "/home/inoribea/.local/bin/aqc", line 8, in
sys.exit(cli())
File "/home/inoribea/.local/share/pipx/venvs/astroquery-cli/lib/python3.13/site-packages/astroquery_cli/main.py", line 283, in cli
setup_subcommands()
File "/home/inoribea/.local/share/pipx/venvs/astroquery-cli/lib/python3.13/site-packages/astroquery_cli/main.py", line 69, in setup_subcommands
from .modules import (
...
)
File "/home/inoribea/.local/share/pipx/venvs/astroquery-cli/lib/python3.13/site-packages/astroquery_cli/modules/simbad_cli.py", line 4, in
from astroquery.simbad import Simbad, SimbadClass
File "/home/inoribea/.local/share/pipx/venvs/astroquery-cli/lib/python3.13/site-packages/astroquery/__init__.py", line 42, in
log = _init_log()
File "/home/inoribea/.local/share/pipx/venvs/astroquery-cli/lib/python3.13/site-packages/astroquery/logger.py", line 16, in _init_log
log._set_defaults()
^^^^^^^^^^^^^^^^^
AttributeError: 'Logger' object has no attribute '_set_defaults'

Contributor guide

Open the contributing guide

Research direction

Start in astroquery/logger.py at _init_log and the log._set_defaults() call, following the import chain shown in the traceback from astroquery/__init__.py. Compare the logger type and dependency resolution in the failing Python environments with the working Poetry environment, then verify that importing astroquery no longer raises AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.