actualbudget / actualbudget/actual

[Bug]: importTransactions API won't check for duplicates in same import

Đang mở
#4,280 2 bình luận 1 reaction 0 người được giao Xem trên GitHub
API
Ngôn ngữ chính
TypeScript
Star
28.7k
Fork
3k
Merge trung bình
2 ngày 11 giờ
Pull request đã merge (30 ngày)
65

Mô tả

### Verified issue does not already exist?

- [x] I have searched and found no existing issue

### What happened?

I'm currently writing an CSV importer and noticed a minor bug in the importTransactions API function.

I created a hash from an row in the CSV file to detect duplicates and to create the `imported_id`.

If a duplicated transaction with the same `imported_id` is imported in the same importTransactions API call, it will still be imported. If the calls are after each other, it works just fine how it should.

### How can we reproduce the issue?

POC Code

```js
import * as api from "@actual-app/api";
import fs from "fs";
import dotenv from "dotenv";

dotenv.config();

const SERVER_URL = process.env.SERVER_URL;
const ACTUAL_PASSWORD = process.env.ACTUAL_PASSWORD;
const SYNC_ID = process.env.SYNC_ID;
const E2E_PASSWORD = process.env.E2E_PASSWORD;

async function testImportTransactions() {
const cacheDir = './local-budgets-cache';
if (!fs.existsSync(cacheDir)) {
fs.mkdirSync(cacheDir, { recursive: true });
console.log(`✔ Created missing directory: ${cacheDir}`);
}

await api.init({
dataDir: cacheDir,
serverURL: SERVER_URL,
password: ACTUAL_PASSWORD,
});

await api.downloadBudget(SYNC_ID, E2E_PASSWORD ? { password: E2E_PASSWORD } : undefined);

// Create a new test account
const accountId = await api.createAccount({ name: "Testaccount" });

// Import transactions at the same time with the same imported_id
let result = await api.importTransactions(accountId, [
{
date: "2024-02-01",
amount: 10000, // 100.00
notes: "#1",
imported_id: "duplicate-id",
},
{
date: "2024-02-02",
amount: 20000, // 200.00
notes: "#2",
imported_id: "duplicate-id",
}
]);

// Import transactions separately with the same imported_id
result = await api.importTransactions(accountId, [
{
date: "2024-02-03",
amount: 10000, // 100.00
notes: "#3",
imported_id: "duplicate-id-2",
}
]);
result = await api.importTransactions(accountId, [
{
date: "2024-02-04",
amount: 20000, // 200.00
notes: "#4",
imported_id: "duplicate-id-2",
}
]);

await api.shutdown();
}

// Run the test
testImportTransactions().catch(console.error);
```


Result: `#1`, `#2` and `#3` are created.
Expected behaviour: `#1` and `#3` are created.

### Where are you hosting Actual?

Docker

### What browsers are you seeing the problem on?

_No response_

### Operating System

None

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.