Skip to content

Allow to add new resource with replace=true#273

Open
Rafnuss wants to merge 5 commits into
frictionlessdata:mainfrom
Rafnuss:allow-to-add-new-resource-with-`replace=TRUE`
Open

Allow to add new resource with replace=true#273
Rafnuss wants to merge 5 commits into
frictionlessdata:mainfrom
Rafnuss:allow-to-add-new-resource-with-`replace=TRUE`

Conversation

@Rafnuss

@Rafnuss Rafnuss commented Dec 28, 2024

Copy link
Copy Markdown

Solution for #259.

We could rename all replace by overwrite but maybe not?

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (cab79a3) to head (66caf0f).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #273   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines          670       678    +8     
=========================================
+ Hits           670       678    +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PietrH

PietrH commented Jun 11, 2026

Copy link
Copy Markdown
Member

Instead of setting replace to FALSE when a new resource is added, I made a small change in the way the resource is added to take the replace switch entirely out of the equation. Now it's only used to return an error early, and if it passes that check:

 Check resource does not exist yet for replace = FALSE
  if (!replace && resource_name %in% resource_names(package)) {
    cli::cli_abort(
      c(
        "{.arg package} already contains a resource named
        {.val {resource_name}}.",
        "i" = "Use {.arg replace = TRUE} to replace an existing resource."
      ),
      class = "frictionless_error_resource_already_exists"
    )
  }

It'll allow for both overwriting or replacing.

This seems like a more elegant solution to me and fixes the bug. The proposed solution seems more difficult to maintain to me because the replace switch differs from the user provided value even when no replacement is taking place.

@PietrH PietrH requested a review from peterdesmet June 11, 2026 14:11
@PietrH PietrH self-assigned this Jun 11, 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.

add_resource(replace = TRUE) fails silently if resource does not exist

2 participants