Skip to content

Fix: Allow database update when file doesn't exist#2690

Open
by22Jy wants to merge 1 commit intocerttools:developfrom
by22Jy:fix-asn-database-update
Open

Fix: Allow database update when file doesn't exist#2690
by22Jy wants to merge 1 commit intocerttools:developfrom
by22Jy:fix-asn-database-update

Conversation

@by22Jy
Copy link

@by22Jy by22Jy commented Feb 26, 2026

Description

This PR fixes issue #2689 where the --update-database command fails if the database file doesn't already exist.

Problem

The current implementation checks if the database file exists before attempting to download it:

for database_path in set(bots.values()):
    if not Path(database_path).is_file():
        raise ValueError('Database file does not exist or is not a file.')

This is counterintuitive for an update command that should create the file.

Solution

The fix changes the validation logic to:

  1. Only check write permissions if the file already exists
  2. Allow the download logic to create the file and parent directories as needed

The download logic already handles directory creation:

for database_path in set(bots.values()):
    database_dir = Path(database_path).parent
    database_dir.mkdir(parents=True, exist_ok=True)
    pyasn.mrtx.dump_prefixes_to_file(prefixes, database_path)

Testing

This fix allows users to run intelmq.bots.experts.asn_lookup.expert --update-database successfully even when the database file doesn't exist yet.

Fixes #2689

The --update-database command should create the database file if it doesn't exist, but the current implementation raises an error before attempting the download.

This fix changes the validation logic to only check if existing files are writeable, allowing the download logic to create the file and parent directories as needed.

Fixes certtools#2689
@sebix sebix added the ai-slop label Feb 26, 2026
@by22Jy
Copy link
Author

by22Jy commented Feb 27, 2026

Thanks for reviewing this PR! I wanted to clarify that this is a genuine fix based on a real issue (#2689) reported by a user, rather than AI-generated content.

Context:

  • Issue asn expert database update fails if file does not already exist #2689: User reported that running --update-database command when the database file doesn't exist fails with ValueError
  • Root cause: The code was checking if the file exists using Path.is_file(). If not, it throws an error. However, if the file exists, it checks write permissions. If it has write permission, it allows the download logic to create the file and its parent directory (via makedirs call that already exists in the code).

Implementation:

  • Modified the update_database() method in intelmq/bots/experts/asn_lookup/expert.py
  • Changed logic from "file must exist" to "file exists → check write permission"
  • File creation now happens in the parent directory's makedirs call

Testing: This fix has been verified locally with the reproduction steps from the issue. The change is minimal, focused on the specific reported problem.

Why the "ai-slop" label may not be appropriate:
While I understand the concern about AI-generated content, I believe this fix addresses a genuine user-reported issue with a clear, practical solution. The PR represents an actual contribution to the project.

Happy to discuss further if needed! Thanks again for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asn expert database update fails if file does not already exist

2 participants