Official Vikunja import
Go to file
Copilot 7cf2a6886e
fix: clear error when duplicating project with uploaded background (#1926)
Resolves https://github.com/go-vikunja/vikunja/issues/1745

- [x] Understand the issue from GitHub issue #1745
- [x] Analyze the codebase to locate the bug in
`duplicateProjectBackground` function
- [x] Fix the bug: return nil explicitly at the end of
duplicateProjectBackground
- [x] Add test for duplicating a project with an uploaded background (as
subtest)
- [x] Run tests and verify the fix
- [x] Run code review and address any feedback
- [x] Run CodeQL security scan

## Summary of Changes

### Problem
When duplicating a project with an uploaded (non-Unsplash) background
image, users encounter an internal server error (HTTP 500). The backend
logs show: `file was not downloaded from unsplash [FileID: X]`

### Root Cause
The `duplicateProjectBackground` function in
`pkg/models/project_duplicate.go` uses named returns. When
`GetUnsplashPhotoByFileID` returns `ErrFileIsNotUnsplashFile` for an
uploaded background, the error was intentionally ignored (to proceed
with copying the file) but not cleared from the named return variable.
This caused the error to be returned at the end of the function via the
bare `return` statement, triggering a 500 response.

### Solution
Changed the bare `return` at the end of `duplicateProjectBackground` to
`return nil` explicitly.

### Changes
1. **`pkg/models/project_duplicate.go`**: Changed bare `return` to
`return nil` at the end of `duplicateProjectBackground`
2. **`pkg/models/project_duplicate_test.go`**: Added subtest "duplicate
project with uploaded background" to `TestProjectDuplicate`

### Testing
- All existing tests pass
- Added subtest to `TestProjectDuplicate` for uploaded background
scenario (project 35 with non-Unsplash background)

### Security Summary
- No security vulnerabilities found by CodeQL
- Code review passed

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>

> # Duplicate project with uploaded background - Implementation Plan
> 
> ## Overview
> Users encounter an internal server error when duplicating a project
that uses an uploaded background image (non-Unsplash). The b
> ackend attempt to copy the background leaves a non-Unsplash error
(`ErrFileIsNotUnsplashFile`) in a named return value, causing
> the duplication API call to fail even though the error should be
ignored. We need to adjust the duplication flow to allow upload
> ed backgrounds and add regression tests.
> 
> ## Current State Analysis
> - Project duplication calls `duplicateProjectBackground` to copy the
background file. The helper tries to copy a downloaded Unsp
> lash image and returns `ErrFileIsNotUnsplashFile` for uploaded files.
> - In the duplication code, the error variable is not cleared after
intentionally ignoring this specific error, so the function s
> till returns the error and triggers a 500 response.
> - There are no automated regression tests covering project duplication
with uploaded backgrounds.
> 
> ### Key Discoveries
> - The duplication logic treats Unsplash and uploaded backgrounds
differently and only clears the Unsplash download error, leavin
> g the non-Unsplash error set.
> - The API currently works for Unsplash backgrounds but fails for
uploaded backgrounds due to the lingering error value.
> 
> ## Desired End State
> - Duplicating a project succeeds for both Unsplash and uploaded
backgrounds.
> - Uploaded background files (and their metadata) are copied correctly
to the new project when possible, or gracefully skipped wi
> thout failing duplication.
> - Regression tests cover duplication with both background types to
prevent future regressions.
> 
> ## What We're NOT Doing
> - No changes to the background upload endpoints or UI selection
workflow.
> - No changes to Unsplash download behavior or quota handling.
> - No new migration or database schema changes.
> 
> ## Implementation Approach
> 1. Fix backend duplication error handling so uploaded backgrounds do
not cause a fatal error.
> 2. Add backend tests to cover duplication with uploaded backgrounds
and Unsplash backgrounds (success paths) and verify duplicat
> ion works without returning 500 errors.
> 3. Ensure tests document the expected behavior and guard against
regressions.
> 
> ## Phase 1: Fix duplication error handling
> ### Overview
> Make project duplication tolerate uploaded backgrounds by clearing or
not propagating `ErrFileIsNotUnsplashFile` once it has bee
> n intentionally ignored.
> 
> ### Changes Required
> - **File:** `pkg/models/projects.go` (or relevant duplication helper)
> - Adjust `duplicateProjectBackground` (or the calling logic) to reset
the named return error after handling `ErrFileIsNotUnspl
> ashFile`, ensuring the function returns `nil` when no real error
occurs.
> - Keep existing behavior for other errors and for Unsplash downloads.
> 
> ### Success Criteria
> - Uploaded background duplication no longer returns an internal server
error.
> - Unsplash background duplication remains functional and still
surfaces real errors.
> 
> ## Phase 2: Add regression tests
> ### Overview
> Add automated tests verifying project duplication works for both
uploaded and Unsplash backgrounds.
> 
> ### Changes Required
> - **File:** `pkg/models/projects_test.go` (or closest existing test
file for project duplication)
> - Add a test that sets up a project with an uploaded background file,
duplicates the project, and asserts duplication succeeds
>  and the duplicated project has an appropriate background reference.
> - Add/adjust test coverage for Unsplash background duplication to
confirm unchanged behavior.
> - Use existing fixtures or temporary files as needed for uploaded
background setup.
> 
> ### Success Criteria
> - Tests fail on current main branch but pass after the fix.
> - Tests validate that duplication completes without 500 errors for
both background types.
> 
> ## Testing Strategy
> - Automated Go tests via `mage test:filter` targeting the new
duplication tests.
> - Optionally run the broader suite (`mage test:feature`) if time
permits to ensure no regressions.
> 
> ## Manual Verification
> 1. Create a project and upload a background via the UI; duplicate it;
observe duplication succeeds and background is present or
> gracefully handled.
> 2. Create a project with an Unsplash background; duplicate it; verify
duplication succeeds.
> 3. Check API responses for duplication calls to ensure no internal
server errors.


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: kolaente <13721712+kolaente@users.noreply.github.com>
2025-12-04 10:16:16 +01:00
.github chore(deps): update actions/checkout digest to 8e8c483 (#1922) 2025-12-03 11:23:29 +01:00
.vscode feat(dev): add frontend and api to launch config 2025-06-19 14:54:08 +02:00
.zed fix(dev): zed frontend task 2025-06-26 12:32:04 +02:00
build fix(release): use openrc for alpine (#1016) 2025-06-25 10:40:11 +00:00
contrib feat: improve clean-translations script (#964) 2025-06-16 19:31:41 +00:00
desktop chore(deps): update js-yaml 2025-12-02 10:39:36 +01:00
examples/plugins/example feat(plugins): allow plugins to register routes 2025-08-01 17:06:02 +02:00
frontend chore(i18n): update translations via Crowdin 2025-12-04 00:57:27 +00:00
pkg fix: clear error when duplicating project with uploaded background (#1926) 2025-12-04 10:16:16 +01:00
rest chore: add missing eof newlines (#969) 2025-06-17 09:11:32 +00:00
.devcontainer.json chore(dev): use latest devenv docker container for devcontainer 2025-07-02 20:17:29 +02:00
.dockerignore Revert "feat: improve docker layers (#803)" 2025-05-21 10:18:57 +02:00
.editorconfig chore(dev): insert final newline 2025-05-23 11:56:50 +02:00
.envrc chore: add missing eof newlines (#969) 2025-06-17 09:11:32 +00:00
.gitignore chore(plugins): ignore plugins dev folder 2025-08-01 17:06:02 +02:00
.golangci.yml feat!: rename right to permission (#1277) 2025-08-13 11:05:05 +02:00
AGENTS.md docs: update AI instructions about plans 2025-11-27 22:24:40 +01:00
CHANGELOG.md chore: 1.0.0-rc3 release preparations 2025-11-27 23:08:01 +01:00
CLAUDE.md docs: add AGENTS.md file with instructions for AI coding agents 2025-06-10 14:23:55 +02:00
CONTRIBUTING.md chore: update contributing guidelines 2023-10-10 17:48:10 +02:00
CRUSH.md docs: add link for crus coding agent instructions 2025-08-01 16:52:30 +02:00
Dockerfile chore(deps): update node.js to 2867d55 (#1815) 2025-11-14 11:17:46 +01:00
LICENSE fix: correct license header references (#882) 2025-06-10 12:18:38 +02:00
README.md chore: 1.0.0-rc3 release preparations 2025-11-27 23:08:01 +01:00
cliff.toml fix: add \n between scoped and unscoped commits in git cliff config 2024-11-08 11:19:50 +01:00
code-header-template.txt fix: correct license header references (#882) 2025-06-10 12:18:38 +02:00
config-raw.json feat: allow setting dark custom logo 2025-11-12 21:07:01 +01:00
crowdin.yml chore: add missing eof newlines (#969) 2025-06-17 09:11:32 +00:00
devenv.lock chore: update devenv 2025-11-24 22:47:21 +01:00
devenv.nix feat: migrate cypress e2e tests to playwright (#1739) 2025-11-27 16:34:48 +01:00
devenv.yaml feat: switch from nix flakes to devenv 2024-08-12 12:17:31 +02:00
go.mod fix(deps): update module github.com/spf13/cobra to v1.10.2 (#1927) 2025-12-04 09:07:54 +01:00
go.sum fix: clear error when duplicating project with uploaded background (#1926) 2025-12-04 10:16:16 +01:00
magefile.go chore(deps): update golangci-lint to 2.6.0 (#1737) 2025-10-31 17:28:52 +00:00
main.go fix: correct license header references (#882) 2025-06-10 12:18:38 +02:00
nfpm.yaml fix(release): use openrc for alpine (#1016) 2025-06-25 10:40:11 +00:00
publiccode.yml docs: update publiccode.yml [skip ci] 2024-02-25 14:06:23 +01:00
renovate.json chore(deps): do not update services as often 2025-06-11 14:38:07 +02:00
tools.go chore(deps): update golangci-lint to 2.6.0 (#1737) 2025-10-31 17:28:52 +00:00
tsconfig.json fix: correct trailing comma in tsconfig (#970) 2025-06-26 12:30:24 +00:00
vikunja.initd fix(release): use openrc for alpine (#1016) 2025-06-25 10:40:11 +00:00
vikunja.service chore: add missing eof newlines (#969) 2025-06-17 09:11:32 +00:00

README.md

Build Status License: AGPL-3.0-or-later Install Docker Pulls Swagger Docs Go Report Card

Vikunja

The Todo-app to organize your life.

If Vikunja is useful to you, please consider buying me a coffee, sponsoring me on GitHub or buying a sticker pack. I'm also offering a hosted version of Vikunja if you want a hassle-free solution for yourself or your team.

Table of contents

Security Reports

If you find any security-related issues you don't want to disclose publicly, please use the contact information on our website.

Features

See the features page on our website for a more exhaustive list or try it on try.vikunja.io!

Docs

All docs can be found on the Vikunja home page.

Roadmap

See the roadmap (hosted on Vikunja!) for more!

Contributing

Please check out the contribution guidelines on the website.

License

Most of this repository is licensed under AGPL3.0orlater. The contents of desktop/ are licensed under GPL3.0orlater.

Unsplash Images

Background images from Unsplash are distributed under the Unsplash License. The license requires giving credit to the photographer and Unsplash. See Unsplashs terms for more information.