Skip to content

Conversation

@ilongin
Copy link
Contributor

@ilongin ilongin commented Jun 26, 2025

Fixing issue on creating missing default project on empty DB.

Summary by Sourcery

Ensure that default and listing projects are automatically created when accessed on an empty database and update test infrastructure to parameterize project/namespace creation permissions.

Bug Fixes:

  • Fix creation of the missing default project on an empty database by forcing creation in metastore.get_project.

Enhancements:

  • Automatically allow creation of default and listing projects in Metastore.get_project().
  • Replace disable_autouse markers with explicit allow_create_project and allow_create_namespace fixtures.

Tests:

  • Add fixtures to control project/namespace creation permissions and parameterize existing tests over those flags.
  • Introduce a new test for saving a dataset to the default project via read_storage.
  • Update tests for project and namespace creation to assert errors when creation is disallowed.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 26, 2025

Reviewer's Guide

Implements automatic creation of missing default and listing projects by extending metastore logic, and refactors tests to parameterize project/namespace creation permissions and cover a new save-to-default-project storage path.

Sequence diagram for automatic creation of default and listing projects

sequenceDiagram
    participant Caller
    participant Metastore
    participant DB

    Caller->>Metastore: get_project(name, namespace_name)
    alt name/namespace is default or listing
        Metastore->>Metastore: _is_listing_project() / _is_default_project()
        Metastore->>Metastore: set create = True
    end
    Metastore->>DB: Query for project
    alt Project does not exist and create=True
        Metastore->>DB: Create project
    end
    Metastore->>Caller: Return project
Loading

Class diagram for updated Metastore project creation logic

classDiagram
    class Metastore {
        +create_project(name, namespace, ...)
        +get_project(name, namespace_name, create=False, conn=None)
        -_is_listing_project(project_name, namespace_name) bool
        -_is_default_project(project_name, namespace_name) bool
        -listing_project_name
        -system_namespace_name
        -default_project_name
        -default_namespace_name
    }

    Metastore : get_project() now always creates default/listing projects if missing
    Metastore : _is_listing_project() added
    Metastore : _is_default_project() added
Loading

File-Level Changes

Change Details Files
Enhance metastore to auto-create default and listing projects
  • Introduce _is_listing_project and _is_default_project helper methods
  • Adjust get_project to always set create=True for default/listing projects
src/datachain/data_storage/metastore.py
Refactor tests to parameterize creation permissions and add coverage
  • Add allow_create_project and allow_create_namespace fixtures
  • Replace disable_autouse markers with allow_create_* parametrization
  • Update mock_allowed_to_create_* fixtures to use new flags
  • Add test for saving via read_storage to default project
tests/unit/lib/test_datachain.py
tests/conftest.py
tests/unit/lib/test_namespace.py
tests/unit/lib/test_project.py

Possibly linked issues


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

@ilongin ilongin linked an issue Jun 26, 2025 that may be closed by this pull request
@ilongin ilongin requested a review from dreadatour June 26, 2025 10:37
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jun 26, 2025

Deploying datachain-documentation with  Cloudflare Pages  Cloudflare Pages

Latest commit: dc8d493
Status: ✅  Deploy successful!
Preview URL: https://ca6ca20b.datachain-documentation.pages.dev
Branch Preview URL: https://ilongin-1180-default-project.datachain-documentation.pages.dev

View logs

Copy link
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 @ilongin - I've reviewed your changes - here's some feedback:

  • You can eliminate the repeated @pytest.mark.parametrize decorators by turning allow_create_project and allow_create_namespace into parametrized fixtures (e.g. @pytest.fixture(params=[True, False])), which reduces boilerplate in each test.
  • Please update the get_project docstring to note that default and listing projects are always auto-created when missing, so readers know why create gets forced to True in those cases.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You can eliminate the repeated @pytest.mark.parametrize decorators by turning allow_create_project and allow_create_namespace into parametrized fixtures (e.g. `@pytest.fixture(params=[True, False])`), which reduces boilerplate in each test.
- Please update the get_project docstring to note that default and listing projects are always auto-created when missing, so readers know why `create` gets forced to True in those cases.

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.

@codecov
Copy link

codecov bot commented Jun 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.68%. Comparing base (6e9d0e2) to head (dc8d493).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1181   +/-   ##
=======================================
  Coverage   88.68%   88.68%           
=======================================
  Files         152      152           
  Lines       13518    13524    +6     
  Branches     1873     1874    +1     
=======================================
+ Hits        11988    11994    +6     
  Misses       1088     1088           
  Partials      442      442           
Flag Coverage Δ
datachain 88.62% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/datachain/data_storage/metastore.py 94.28% <100.00%> (+0.06%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@dreadatour dreadatour left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍 Thank you for the fix ❤️

@ilongin ilongin merged commit 2c92a33 into main Jun 26, 2025
35 checks passed
@ilongin ilongin deleted the ilongin/1180-default-project-issue branch June 26, 2025 11:55
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.

Issue when using read_storage with default project

2 participants