Skip to content

Refactor item_id retrieval logic in operation logging#305

Merged
osmith42 merged 2 commits into
nickvsnetworking:masterfrom
Robin-Rhee:master
Jan 28, 2026
Merged

Refactor item_id retrieval logic in operation logging#305
osmith42 merged 2 commits into
nickvsnetworking:masterfrom
Robin-Rhee:master

Conversation

@Robin-Rhee

@Robin-Rhee Robin-Rhee commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

Hi,
Nick,

This PR was originated from a resolution to a Q&A discussion in the docker_open5gs repo.

  1. Refactor item_id assignment to avoid using 'or' expression and ensure proper handling of item_id.

The "or" expression means by the following logic

if bool(item_id) is True:
    return item_id
else:
    return generated_id

So if the item_id is 0, it would be treated as false, which causes the item_id to get the value of generated_id (None).
This triggers the mysql to return error because the item_id should be non-null as defined in the schema.

  1. Change the sequence of getattr() and session.flush()

The item_id should invoke getattr() after session flush, thereafter the beforehand APN insertion can be presented to the DB.
In this way, the getattr function can actually get the apn_id of an existent APN record.

- Refactor item_id assignment to avoid using 'or' expression and ensure proper handling of item_id.
- Change the sequence of getattr() and session.flush()
@osmith42

Copy link
Copy Markdown
Collaborator

Looking at how this works, users can send their own ID to the API call for adding an APN and they can choose 0 as ID. (I was a bit surprised by this, since auto-incrementing integers in databases start at 1 and docs/provisioning.md talks about using APNs with IDs 1 and 2.)

So this looks good to me, I would only adjust the comment to explain why or is not used here (or remove the comment line entirely).

Thanks for sending this fix!

Comment thread lib/database.py Outdated
fine-tune a comment

Co-authored-by: Oliver Smith <osmith@sysmocom.de>
@Robin-Rhee

Copy link
Copy Markdown
Contributor Author

Looking at how this works, users can send their own ID to the API call for adding an APN and they can choose 0 as ID. (I was a bit surprised by this, since auto-incrementing integers in databases start at 1 and docs/provisioning.md talks about using APNs with IDs 1 and 2.)

So this looks good to me, I would only adjust the comment to explain why or is not used here (or remove the comment line entirely).

Thanks for sending this fix!

Thank you very much, Oliver !!
Just made the fine tune in line with your request.

@osmith42 osmith42 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks again!

@osmith42 osmith42 merged commit b1534c3 into nickvsnetworking:master Jan 28, 2026
6 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.

2 participants