Skip to content

Conversation

@pranavxc
Copy link
Member

@pranavxc pranavxc commented Mar 4, 2025

Change Summary

Change type

  • feat: (new feature for the user, not a new feature for build script)
  • fix: (bug fix for the user, not a fix to a build script)
  • docs: (changes to the documentation)
  • style: (formatting, missing semi colons, etc; no production code change)
  • refactor: (refactoring production code, eg. renaming a variable)
  • test: (adding missing tests, refactoring tests; no production code change)
  • chore: (updating grunt tasks etc; no production code change)

Test/ Verification

Provide summary of changes.

Additional information / screenshots (optional)

Anything for maintainers to be made aware of

@pranavxc pranavxc requested a review from fendy3002 March 4, 2025 12:52
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

📝 Walkthrough

Walkthrough

The changes update the primary key extraction process in the audit logging of the BaseModelSqlv2 class. The row_id is now set by calling the extractPksValues method rather than directly using the id variable. Additionally, the extractPksValues method now includes a check to immediately return the incoming data if it is not an object, ensuring more robust handling of non-object inputs.

Changes

File(s) Change Summary
packages/nocodb/.../BaseModelSqlv2.ts Modified audit logging to populate row_id using extractPksValues instead of a direct id reference. Added a type-check in extractPksValues to handle non-object data.

Sequence Diagram(s)

sequenceDiagram
  participant AL as Audit Logger
  participant BM as BaseModelSqlv2

  AL->>BM: Initiate audit operation with data payload
  BM->>BM: Call extractPksValues(data)
  alt Data is object
    BM->>BM: Process to extract primary key values
  else Data is not an object
    BM->>BM: Return data as-is
  end
  BM-->>AL: Return extracted row_id for logging
Loading

Possibly related PRs

Suggested labels

🐛 Type: Bug, 🍰 Scope : Column, size:M, lgtm

Suggested reviewers

  • mertmit
  • dstala

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14a3ded and 6dacf0b.

📒 Files selected for processing (1)
  • packages/nocodb/src/db/BaseModelSqlv2.ts (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: release-docker / buildx
  • GitHub Check: pre-build-for-playwright / playwright
  • GitHub Check: unit-tests-pg
  • GitHub Check: unit-tests
🔇 Additional comments (8)
packages/nocodb/src/db/BaseModelSqlv2.ts (8)

7623-7625: Good defensive programming with early return

This addition properly handles the case when data is not an object, returning it as-is instead of trying to extract properties from it. This prevents potential errors when extractPksValues is called with primitive values.


7630-7639: Robust handling of composite primary keys

The implementation correctly extracts values from both title and column_name properties with fallback, ensuring the method works regardless of which property name is used in the input data. For composite keys, returning either the object with all primary key values or a properly formatted string (when asString=true) is a good approach.


7635-7638: Proper escaping in composite key string representation

The code correctly escapes underscores in the values before joining them with ___ separator. This is important to ensure we can reliably split the composite key string back into its component values if needed.


7206-7207: Fixed audit record row_id for insert operations

Now correctly using extractPksValues to properly format the primary key (whether simple or composite) for the audit record. This ensures row_id is stored consistently even with tables that use composite primary keys.


7313-7314: Fixed audit record row_id for delete operations

Using extractPksValues with asString=true consistently ensures that composite primary keys are properly serialized in the audit logs, making it possible to reference the deleted records correctly.


7994-7995: Fixed audit record row_id for link operations

This change ensures composite primary keys are properly handled when recording link operations between records in audit logs. The explicit type cast to string ensures TypeScript type safety.


8120-8121: Fixed audit record row_id for unlink operations

Consistent with the other fixes, this change ensures composite primary keys are correctly serialized when recording unlink operations in audit logs.


10934-10935: Fixed audit record row_id for bulk update operations

Using extractPksValues with asString=true here ensures that even in bulk operations, each affected row's composite primary key is properly serialized in the audit logs.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2025

Uffizzi Ephemeral Environment Deploying

☁️ https://app.uffizzi.com/github.com/nocodb/nocodb/pull/10704

⚙️ Updating now by workflow run 13654258346.

What is Uffizzi? Learn more!

@fendy3002 fendy3002 merged commit 1cce2f2 into develop Mar 5, 2025
23 checks passed
@fendy3002 fendy3002 deleted the nc-fix/composite-pk-audit branch March 5, 2025 08:27
@coderabbitai coderabbitai bot mentioned this pull request Mar 27, 2025
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.

🐛 Bug: audit log do not retrieved correctly for composite pk

3 participants