Skip to content

Conversation

winstonallo
Copy link
Contributor

Description

Prevents a (probably mistakenly created) config.yml/ directory from being attempted to open as a regular file, resulting in a misleading PermissionError (source: just happened to me).

Before: PermissionError: [Errno 13] Permission denied: 'config.yml'
After: config.yml/ directory is treated as a valid config directory (falls through to existing directory handling logic).

Copy link
Collaborator

@trebedea trebedea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Nice catch 👍

@Pouyanpi Pouyanpi requested a review from Copilot July 18, 2025 11:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where a directory with a .yml or .yaml extension would be incorrectly treated as a configuration file, causing a misleading PermissionError when attempting to open it. The fix adds an explicit file check to ensure only actual files with these extensions are processed as YAML config files, while directories fall through to the existing directory handling logic.

  • Added os.path.isfile() check to prevent directories with YAML extensions from being treated as config files
  • Maintains existing functionality for actual YAML config files
  • Improves error handling and user experience when config directories are mistakenly created with YAML extensions

@Pouyanpi
Copy link
Collaborator

@winstonallo thanks! would you please run the pre-commits per the contributing guideline.

Also this PR misses a regression test covering the directory with yml extension scenario

so a test case like:

def test_yaml_directory_handling():
    # like create a directory named whatever_config.yml
    # verify it's handled as a directory, not a file

this test should fail on the develop branch prior to this PR and go green afterwards.

@winstonallo
Copy link
Contributor Author

Hey, sorry for the late response, I will get to that on Wednesday:)

@winstonallo
Copy link
Contributor Author

Hey @Pouyanpi, I added the test and ran the pre-commit hooks:) Let me know if there is anything else I can do

@codecov-commenter
Copy link

codecov-commenter commented Jul 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.63%. Comparing base (cd14a07) to head (45d1d00).
⚠️ Report is 19 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1293      +/-   ##
===========================================
+ Coverage    70.20%   70.63%   +0.42%     
===========================================
  Files          161      161              
  Lines        16123    16304     +181     
===========================================
+ Hits         11319    11516     +197     
+ Misses        4804     4788      -16     
Flag Coverage Δ
python 70.63% <ø> (+0.42%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
nemoguardrails/rails/llm/config.py 90.55% <ø> (+0.23%) ⬆️

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@winstonallo winstonallo reopened this Jul 23, 2025
@Pouyanpi Pouyanpi added this to the v0.16.0 milestone Aug 1, 2025
@Pouyanpi
Copy link
Collaborator

@winstonallo Thanks for adding the tests! I thought it might be better to just use a temp dir and file. Since your changes are on the develop branch of your fork, I couldn't make any changes or push directly.

Could you please add

import tempfile
from pathlib import Path

at the top of test_rails_config.py, then run

poetry run pre-commit run --all-files

and push the changes? Thanks!

@winstonallo
Copy link
Contributor Author

Done @Pouyanpi :)

Copy link
Collaborator

@Pouyanpi Pouyanpi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you @winstonallo for your contribution. Looking forward to collaborating more in the future 🚀

@Pouyanpi Pouyanpi merged commit 52ac7ed into NVIDIA:develop Aug 15, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants