Skip to content

Fix autotailor json bugs#2318

Open
Mab879 wants to merge 1 commit intoOpenSCAP:mainfrom
Mab879:fix_autotail_json_bugs
Open

Fix autotailor json bugs#2318
Mab879 wants to merge 1 commit intoOpenSCAP:mainfrom
Mab879:fix_autotail_json_bugs

Conversation

@Mab879
Copy link
Copy Markdown
Member

@Mab879 Mab879 commented Mar 2, 2026

No description provided.

@jan-cerny jan-cerny self-assigned this Mar 26, 2026
@Mab879 Mab879 force-pushed the fix_autotail_json_bugs branch from a1a18c2 to 30b68d2 Compare March 27, 2026 15:39
if not profile_dict.get("base_profile_id") and not profile_dict.get("id"):
raise ValueError("You must define a base_profile_id or an id")
self.extends = profile_dict.get("base_profile_id")
self.profile_id = profile_dict.get("id")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can the self.profile_id be None after this assignment?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, there is a None check at 289.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

On second look, it could, but this handled in get the getter for profile_id.

@Mab879 Mab879 force-pushed the fix_autotail_json_bugs branch 2 times, most recently from f0251c9 to d559dbb Compare March 30, 2026 19:21
Comment on lines +105 to +108
with open(file_path) as fp:
profile_dict = json.load(fp)
with pytest.raises(ValueError):
p.import_json_tailoring_profile(profile_dict)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like the test accidentally passes, but there is a problem that the JSON isn't the profile object, it's a dictionary where the profiles key contains a list of profile objects.

Suggested change
with open(file_path) as fp:
profile_dict = json.load(fp)
with pytest.raises(ValueError):
p.import_json_tailoring_profile(profile_dict)
with open(file_path) as fp:
json_data = json.load(fp)
profile_dict = json_data["profiles"][0]
with pytest.raises(ValueError) as e:
p.import_json_tailoring_profile(profile_dict)
assert str(e.value) == "You must define a base_profile_id or an id"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

@Mab879 Mab879 force-pushed the fix_autotail_json_bugs branch from d559dbb to 7190c00 Compare March 31, 2026 13:18
@sonarqubecloud
Copy link
Copy Markdown

@Mab879 Mab879 marked this pull request as ready for review March 31, 2026 13:20
@Mab879 Mab879 requested a review from matusmarhefka as a code owner March 31, 2026 13:20
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.

3 participants