Skip to content

Feat/optional project scoping#193

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

Feat/optional project scoping#193
leiflm wants to merge 1 commit 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.

When default_project is intentionally empty, pylero now operates
in global-scope mode without requiring a project to be set:

- _SpecificWorkItem.query(): project filter is only appended when a
  project is actually resolved; pass project_id="" to bypass even a
  configured default_project and get instance-wide results.

- TestRun.search(): same treatment — project filter and custom-field
  initialisation are skipped when no project is resolved.

- _get_enum_options(): normalise "" to None so Polarion treats the
  call as instance-wide (null project), avoiding URI validation errors.

- get_custom_fields(): early-return when project_id is falsy to avoid
  an invalid getDefinedCustomFieldTypes("", …) SOAP call.

- Module-level workitem-type enum fetch and _SpecificWorkItem subclass
  creation are guarded with `if cfg.proj:` so they are skipped entirely
  in global-scope mode.

Assisted-by: Artificial Intelligence
@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.

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