Skip to content

[RTI][TOOL] Unique IDs generation for RTI Requests#153

Open
ChanukaUOJ wants to merge 3 commits into
LDFLK:mainfrom
ChanukaUOJ:feat/rti-request-id-change
Open

[RTI][TOOL] Unique IDs generation for RTI Requests#153
ChanukaUOJ wants to merge 3 commits into
LDFLK:mainfrom
ChanukaUOJ:feat/rti-request-id-change

Conversation

@ChanukaUOJ
Copy link
Copy Markdown
Member

Closes: #151

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request migrates the unique identifier for RTI Requests from UUIDs to auto-incrementing integers across the database schema, backend services, API routers, tests, and frontend components. The review feedback highlights three key issues: first, defining the primary key id in SQLModel without a default value will cause validation errors during instantiation; second, calling self.session.flush() introduces a transaction that is not rolled back when custom exceptions are raised; and third, parsing route parameters with Number(id) can yield NaN for non-numeric URLs, which should be safely handled using parseInt with a fallback.

Comment thread tool/backend/src/models/table_schemas/table_schemas.py Outdated
rti_template_id=request_data.rti_template_id
)
self.session.add(rti_request)
self.session.flush()
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.

high

With the introduction of self.session.flush() before the file upload and status history creation, a database transaction is now active. If any subsequent step fails (such as the file upload failing or the CREATED status not being found in the database), an InternalServerException or other custom exception is raised.

However, the exception handling block at the end of this function catches these custom exceptions and directly re-raises them:

except (BadRequestException, NotFoundException, ConflictException, InternalServerException):
    raise

This bypasses the except Exception as e: block, meaning self.session.rollback() is never called. This leaves the database transaction unrolled-back and can lead to leaked resources, lock contention, or partial/corrupted data being committed later.

To fix this, restructure the exception handling at the end of the function to catch all exceptions, perform the rollback and file cleanup, and then re-raise or map them accordingly.

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.

Noted! Not this exception raising handled inside the the catch block and re-raise the exception based on the exception type

Comment thread tool/frontend/src/pages/RTIDetail.tsx Outdated
@ChanukaUOJ ChanukaUOJ requested a review from zaeema-n May 26, 2026 02:52
@zaeema-n
Copy link
Copy Markdown
Member

Add ability in the frontend to search by the id of the rti request. Currently it only searches by title.

@zaeema-n
Copy link
Copy Markdown
Member

When you view an rti request, the id should be shown on the page.

@zaeema-n
Copy link
Copy Markdown
Member

Remove Active flag from the latest state in each rti requests

@zaeema-n
Copy link
Copy Markdown
Member

Change "TARGET ENTITY" to "RECEIVER" in the rti_request page.

target_id = UUID(request_id) if isinstance(request_id, str) else request_id
except ValueError:
raise BadRequestException(f"Invalid UUID format: {request_id}")
target_id = request_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.

Do we need to do this?

):
request = RTIRequestUpdateRequest(
id=id or str(uuid.uuid4()),
id=id or 99999,
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.

Suggested change
id=id or 99999,
id=id or 999999,

request = RTIRequestUpdateRequest(**fields)
if not id:
request.id = str(uuid.uuid4()) # Ensure ID is always set for service fetch
request.id = 99999 # Ensure ID is always set for service fetch
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.

Suggested change
request.id = 99999 # Ensure ID is always set for service fetch
request.id = 999999 # Ensure ID is always set for service fetch

Comment on lines -79 to -86
@pytest.mark.asyncio
async def test_get_rti_request_histories_not_found(rti_request_db, make_file_service):
"""NotFoundException raised when RTI Request ID doesn't exist."""
service = RTIRequestHistoryService(session=rti_request_db, file_service=make_file_service())

with pytest.raises(NotFoundException) as exc:
service.get_rti_request_histories_by_id(rti_request_id=uuid.uuid4())
assert "not found" in str(exc.value)
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.

Why did we remove this test?


with pytest.raises(NotFoundException) as exc:
await service.create_rti_request_history(rti_request_id=uuid.uuid4(), request_data=request)
await service.create_rti_request_history(rti_request_id=99999, request_data=request)
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.

Suggested change
await service.create_rti_request_history(rti_request_id=99999, request_data=request)
await service.create_rti_request_history(rti_request_id=999999, request_data=request)


with pytest.raises(NotFoundException) as exc:
service.get_rti_request_by_id(request_id=uuid.uuid4())
service.get_rti_request_by_id(request_id=99999)
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.

Suggested change
service.get_rti_request_by_id(request_id=99999)
service.get_rti_request_by_id(request_id=999999)


with pytest.raises(InternalServerException) as exc:
service.get_rti_request_by_id(request_id=uuid.uuid4())
service.get_rti_request_by_id(request_id=99999)
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.

Suggested change
service.get_rti_request_by_id(request_id=99999)
service.get_rti_request_by_id(request_id=999999)

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.

[RTI][TOOL] Unique IDs generation for RTI Requests

2 participants