Skip to content

Feat/optional project scoping#193

Open
leiflm wants to merge 2 commits into
RedHatQE:mainfrom
testo:feat/optional-project-scoping
Open

Feat/optional project scoping#193
leiflm wants to merge 2 commits into
RedHatQE:mainfrom
testo:feat/optional-project-scoping

Conversation

@leiflm

@leiflm leiflm commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Disclaimer

This contribution was created AI assisted. Feel free to reject it right away if it violates your policies.

Problem

PyleroConfig.__init__ requires default_project to be set — either via the POLARION_PROJECT environment variable or as a key in ~/.pylero. If neither is present, config.get() on line 78 raises an unhandled configparser.NoOptionError and the module fails to initialize entirely.

The only valid workaround was to set default_project= (empty string) in ~/.pylero. But the old search methods treated an empty default_project as falsy and fell back to it unconditionally via or, producing a broken Lucene fragment (AND project.id:) that would be rejected by Polarion.

Fix

TestRun.search() and _SpecificWorkItem.query() now distinguish None from "" using an explicit identity check:

resolved_project = project_id if project_id is not None else cls.default_project
if resolved_project:
    query += " AND project.id:%s" % resolved_project

None → falls back to default_project (unchanged for users with a project configured). "" → project filter is omitted, enabling cross-project queries. This makes default_project= in ~/.pylero a valid, well-behaved configuration.

Backwards compatibility

Fully backwards-compatible. Any caller passing a non-empty project_id or relying on a non-empty default_project sees identical behaviour.

@leiflm leiflm force-pushed the feat/optional-project-scoping branch from 476b85e to d16bb97 Compare June 17, 2026 17:10
@leelavg

leelavg commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

sry, I'm a bit confused about the issue? if we were accepting empty string for default_project then that's a bug to be fixed disallowing empty string but not workaround it and anything that's touching the cfg at basepolarion needs a good testing.

AI code is fine but it should be reviewed by the author before posting, on a quick glance it's a bit troublesome to review rest of the code when I see a new if is introduced just to return where the above line also does the same condition.

@leiflm

leiflm commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

sry, I'm a bit confused about the issue? if we were accepting empty string for default_project then that's a bug to be fixed disallowing empty string but not workaround it

the objective is to be able to execute query statements against the global scope. Without these changes queries would fall back to be executed against „default_project“ if no other project was explicitly specified. Working around this limitation by specifiying an empty string as default _project would lead to a crash either in pylero or the Server side.

and anything that's touching the cfg at basepolarion needs a good testing.

Makes sense.

AI code is fine but it should be reviewed by the author before posting, on a quick glance it's a bit troublesome to review rest of the code when I see a new if is introduced just to return where the above line also does the same condition.

Fair enough, my apologies. I’ll manually review and ping again.

leiflm added 2 commits July 11, 2026 13:32
_SpecificWorkItem.query() and TestRun.search() unconditionally append
"AND project.id:<default_project>" to every query, so there is no way
to search the whole Polarion instance even though the underlying
Tracker.queryWorkItems / TestManagement.searchTestRuns services support
it. The other search wrappers (base _WorkItem.query(), Document.query(),
Plan.search()) never scope to a project and leave the query to the
caller, so these two methods are the only ones that need an opt-out.

Add an explicit all_projects keyword argument (default False) to both
methods. When set, the project.id clause is simply not appended and the
query runs instance-wide; combining it with project_id raises
PyleroLibException instead of silently preferring one of them.
Nothing else changes: default_project remains required, custom-field
initialization still uses the default project, and all existing calls
behave exactly as before. Document the scoping behaviour in the README.

Assisted-by: Artificial Intelligence
An absent default_project key (with no POLARION_PROJECT env var) made
Configuration.__init__ crash with an unhandled configparser
NoOptionError, and an empty value slipped through validation only to
break later with cryptic SOAP/query errors (e.g. a dangling
"AND project.id:" clause).

Disallow both explicitly: Configuration now raises PyleroLibException
naming the config files and env var to set, and pointing at
all_projects=True as the supported way to query across projects. The
default_project term in the pre-existing url/credentials check is
dropped because it can no longer be reached, and that check's message
is corrected accordingly.

Add configuration_test.py covering the set/empty/missing/env-var
default_project cases and the url/credentials check; it runs offline
without a Polarion instance
(nose2 -s src/unit_tests configuration_test).

Assisted-by: Artificial Intelligence
@leiflm leiflm force-pushed the feat/optional-project-scoping branch from d16bb97 to 99c2b22 Compare July 13, 2026 12:54
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.

2 participants