Skip to content

Or conditions#1481

Merged
phenobarbital merged 2 commits into
masterfrom
or_conditions
Dec 11, 2025
Merged

Or conditions#1481
phenobarbital merged 2 commits into
masterfrom
or_conditions

Conversation

@phenobarbital
Copy link
Copy Markdown
Owner

@phenobarbital phenobarbital commented Dec 11, 2025

Summary by Sourcery

Add configurable authentication method for the ArangoDB driver and bump the library version.

New Features:

  • Allow selecting the ArangoDB authentication method via an auth_method parameter, supporting basic and JWT auth.

Enhancements:

  • Default ArangoDB driver authentication configuration now includes an auth_method option with sensible defaults.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Dec 11, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds configurable authentication method support (basic or JWT) to the ArangoDB driver connection setup and bumps the library version.

Sequence diagram for ArangoDB connection with configurable authentication method

sequenceDiagram
    participant Client
    participant ArangoDBDriver
    participant ArangoClient
    participant SysDB

    Client->>ArangoDBDriver: __init__(params)
    ArangoDBDriver->>ArangoDBDriver: set _username from params or default
    ArangoDBDriver->>ArangoDBDriver: set _password from params or default
    ArangoDBDriver->>ArangoDBDriver: set _auth_method from params or basic

    Client->>ArangoDBDriver: connection(database)
    ArangoDBDriver->>ArangoDBDriver: build url from _protocol, _host, _port
    ArangoDBDriver->>ArangoClient: ArangoClient(hosts=url)
    ArangoClient-->>ArangoDBDriver: client instance

    alt auth_method is jwt
        ArangoDBDriver->>ArangoDBDriver: token = params.jwt_token or _password
        ArangoDBDriver->>ArangoClient: db(_system, auth_method=jwt, password=token)
        ArangoClient-->>SysDB: create sys_db with jwt
    else auth_method is basic
        ArangoDBDriver->>ArangoClient: db(_system, username=_username, password=_password)
        ArangoClient-->>SysDB: create sys_db with basic
    end

    ArangoDBDriver->>SysDB: databases()
    SysDB-->>ArangoDBDriver: list of databases
    ArangoDBDriver->>SysDB: create or select target database as needed
Loading

Class diagram for ArangoDB driver with basic and JWT authentication support

classDiagram
    class ArangoDBDriver {
        +dict params
        -str _username
        -str _password
        -str _auth_method
        -str _protocol
        -str _host
        -int _port
        -str _database_name
        -ArangoClient _client
        __init__(params)
        connection(database)
    }

    class ArangoClient {
        ArangoClient(hosts)
        db(database_name, username, password)
        db(database_name, auth_method, password)
    }

    class SysDB {
        databases()
    }

    ArangoDBDriver --> ArangoClient : uses
    ArangoClient --> SysDB : returns

    %% Authentication configuration in constructor
    ArangoDBDriver : _auth_method set from params.auth_method or basic

    %% Connection behavior
    ArangoDBDriver : connection uses _auth_method to choose jwt or basic
    ArangoDBDriver : for jwt - token from params.jwt_token or _password
    ArangoDBDriver : for basic - uses _username and _password
Loading

File-Level Changes

Change Details Files
Make ArangoDB driver authentication method configurable between basic and JWT.
  • Read an auth_method parameter from driver configuration, defaulting to basic.
  • Initialize the ArangoDB client as before but branch system database connection logic based on auth_method.
  • For jwt auth_method, obtain a JWT token from jwt_token parameter falling back to password and pass it to the client with auth_method="jwt".
  • For basic auth_method, preserve the existing behavior using username and password for authentication.
asyncdb/drivers/arangodb.py
Update library version to reflect the new feature.
  • Increment version from 2.13.1 to 2.13.2.
asyncdb/version.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@phenobarbital phenobarbital merged commit 4cd8669 into master Dec 11, 2025
2 of 3 checks passed
@phenobarbital phenobarbital deleted the or_conditions branch December 11, 2025 15:33
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • In the __init__ exception path you reset _username and _password but never initialize _auth_method, which can lead to attribute errors later; consider setting _auth_method to a sensible default there as well.
  • In connection, only jwt and basic values for _auth_method are handled; consider validating self._auth_method and raising a clear error or falling back to a default for unsupported values instead of silently doing nothing.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the `__init__` exception path you reset `_username` and `_password` but never initialize `_auth_method`, which can lead to attribute errors later; consider setting `_auth_method` to a sensible default there as well.
- In `connection`, only `jwt` and `basic` values for `_auth_method` are handled; consider validating `self._auth_method` and raising a clear error or falling back to a default for unsupported values instead of silently doing nothing.

## Individual Comments

### Comment 1
<location> `asyncdb/drivers/arangodb.py:112-119` </location>
<code_context>
+                hosts=url
             )
+            # Connect to system database first
+            if self._auth_method == "jwt":
+                token = self.params.get('jwt_token', self._password)
+                sys_db = self._client.db(
+                    '_system',
+                    auth_method="jwt",
+                    password=token
+                )
+            elif self._auth_method == "basic":
+                sys_db = self._client.db(
+                    '_system',
</code_context>

<issue_to_address>
**issue (bug_risk):** Handle unsupported `auth_method` values to avoid `sys_db` being undefined.

If `self._auth_method` is anything other than `"jwt"` or `"basic"`, `sys_db` remains undefined and `sys_db.databases()` will raise `UnboundLocalError`. Consider either defaulting to a supported method or explicitly raising an error for unsupported auth methods.
</issue_to_address>

### Comment 2
<location> `asyncdb/drivers/arangodb.py:111-114` </location>
<code_context>
             )
+            # Connect to system database first
+            if self._auth_method == "jwt":
+                token = self.params.get('jwt_token', self._password)
+                sys_db = self._client.db(
+                    '_system',
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Avoid defaulting the JWT token to the password value.

Reusing `self._password` as the default `jwt_token` risks confusing/failed auth when someone switches to JWT without explicitly setting a token, and mixes two distinct credential types. Prefer requiring an explicit `jwt_token` (and failing fast if it’s missing) rather than silently falling back to the password.

```suggestion
            # Connect to system database first
            if self._auth_method == "jwt":
                token = self.params.get('jwt_token')
                if not token:
                    raise ValueError("jwt_token parameter is required when auth_method is 'jwt'")
                sys_db = self._client.db(
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +112 to +119
if self._auth_method == "jwt":
token = self.params.get('jwt_token', self._password)
sys_db = self._client.db(
'_system',
auth_method="jwt",
password=token
)
elif self._auth_method == "basic":
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Handle unsupported auth_method values to avoid sys_db being undefined.

If self._auth_method is anything other than "jwt" or "basic", sys_db remains undefined and sys_db.databases() will raise UnboundLocalError. Consider either defaulting to a supported method or explicitly raising an error for unsupported auth methods.

Comment on lines +111 to +114
# Connect to system database first
if self._auth_method == "jwt":
token = self.params.get('jwt_token', self._password)
sys_db = self._client.db(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Avoid defaulting the JWT token to the password value.

Reusing self._password as the default jwt_token risks confusing/failed auth when someone switches to JWT without explicitly setting a token, and mixes two distinct credential types. Prefer requiring an explicit jwt_token (and failing fast if it’s missing) rather than silently falling back to the password.

Suggested change
# Connect to system database first
if self._auth_method == "jwt":
token = self.params.get('jwt_token', self._password)
sys_db = self._client.db(
# Connect to system database first
if self._auth_method == "jwt":
token = self.params.get('jwt_token')
if not token:
raise ValueError("jwt_token parameter is required when auth_method is 'jwt'")
sys_db = self._client.db(

phenobarbital added a commit that referenced this pull request Mar 20, 2026
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.

1 participant