Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: importTransactions results in timestamp error #1585

Closed
1 task done
niko123456000 opened this issue Aug 25, 2023 · 17 comments
Closed
1 task done

[Bug]: importTransactions results in timestamp error #1585

niko123456000 opened this issue Aug 25, 2023 · 17 comments
Labels
API Issues with the @actual-app/api package bug Something isn't working

Comments

@niko123456000
Copy link

Verified issue does not already exist?

  • I have searched and found no existing issue

What happened?

Attempting to insert a transaction using the API results in an error.

var api = require('@actual-app/api');
api.init({
  serverURL: '',
  password: ''
});

api.importTransactions(accountId, [{
    account_id: accountId,
    date: "2024-08-23",
    amount: 1200,
    payee: "Kroger"
  }])

Node.js: v20.5.1 on WSL2
Client version: v23.8.1
Server version: v23.8.1

What error did you receive?

/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:31964
                        let latestTimestamp = (0, _actual_app_crdt__WEBPACK_IMPORTED_MODULE_0__.getClock)().timestamp.toString();
                                                                                                           ^

TypeError: Cannot read properties of undefined (reading 'timestamp')
    at undoDisabled (/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:31964:108)
    at _runMutator (/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:41044:24)
    at run (/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:44421:45)
    at sequenceState.queue.push.resolve.resolve (/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:44433:36)
    at new Promise (<anonymous>)
    at /home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:44432:32
    at /home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:31963:83
    at runHandler (/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:41028:31)
    at Object.send (/home/nicholas/app/node_modules/@actual-app/api/dist/app/bundle.api.js:40685:92)
    at send (/home/nicholas/app/node_modules/@actual-app/api/dist/methods.js:34:21)

Node.js v20.5.1

Where are you hosting Actual?

Docker

What browsers are you seeing the problem on?

No response

Operating System

Linux

@niko123456000 niko123456000 added the bug Something isn't working label Aug 25, 2023
@MatissJanis
Copy link
Member

MatissJanis commented Aug 26, 2023

What API version are you using? I just tested against a local instance and also a remote instance. Both worked perfectly fine.

var api = require('@actual-app/api');

const config = {
    serverURL: 'http://localhost:5006',
    password: 'password',
    budgetId: '4e805261-6fdc-4c50-b5f3-fa34876644c8',
    accountId: '76d2ed74-c606-41c2-8f5d-f18a6f99cadc',
};


(async () => {
    await api.init(config);
    await api.downloadBudget(config.budgetId);

    await api.importTransactions(config.accountId, [{
        date: "2024-08-23",
        amount: 1200,
        payee_name: "Kroger"
    }]);

    let budget = await api.getBudgetMonth('2023-08');
    console.log(budget);

    await api.shutdown();
})();

@niko123456000
Copy link
Author

niko123456000 commented Aug 26, 2023 via email

@niko123456000
Copy link
Author

niko123456000 commented Aug 26, 2023 via email

@MatissJanis
Copy link
Member

The latest version is 6.2.1 🤔

https://www.npmjs.com/package/@actual-app/api?activeTab=versions

@niko123456000
Copy link
Author

niko123456000 commented Aug 26, 2023 via email

@MatissJanis
Copy link
Member

The version numbers are masked @niko123456000

@niko123456000
Copy link
Author

The version numbers are masked @niko123456000

sorry! I replied by email, didn't know that was a thing ;)

$ npm list
nicholas@ /home/nicholas
├── @actual-app/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

@MatissJanis
Copy link
Member

I have the exact same set-up as you and things are working perfectly fine for me. So I'm not really sure what the issue might be..

Maybe try running my code snippet posted above against your server?

If that doesn't work - an export of your budget (with redacted information) would be helpful.

@niko123456000
Copy link
Author

I have created a new budget file and I still get the same issues.

If I keep init and downloadBudget I get a 'segementation fault' on node v20 or 'stack smashing detected' on node v18.

in a last ditch attempt I installed node directly into Windows... (not WSL or Pop_OS): it worked.

On Pop_OS I got an error that sqlite was built using a different package version but couldn't really figure out where that was coming from.. it wasn't in my package-lock.json file.

@porjo
Copy link

porjo commented Aug 28, 2023

I'm seeing the same error with api.createAccount(account);

/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:31964
                        let latestTimestamp = (0, _actual_app_crdt__WEBPACK_IMPORTED_MODULE_0__.getClock)().timestamp.toString();
                                                                                                           ^

TypeError: Cannot read properties of undefined (reading 'timestamp')
    at undoDisabled (/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:31964:108)
    at _runMutator (/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:41044:24)
    at run (/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:44421:45)
    at sequenceState.queue.push.resolve.resolve (/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:44433:36)
    at new Promise (<anonymous>)
    at /root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:44432:32
    at /root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:31963:83
    at runHandler (/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:41028:31)
    at Object.send (/root/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:40685:92)
    at send (/root/actual/node_modules/@actual-app/api/dist/methods.js:34:21)

Fedora 38 (Docker container)
Node v18.17.1

 npm list
actual@ /root/actual
└── @actual-app/[email protected]
app.js
let api = require('@actual-app/api');
let data = require('/root/actual/my-data.json');


(async () => {
	await api.init({
		// Budget data will be cached locally here, in subdirectories for each file.
		dataDir: '/tmp',
		// This is the URL of your running server
		serverURL: 'https://example.com',
		// This is the password you use to log into the server
		password: 'xxxxxxxxxxx'
	});

//	async function run() {
		for (let account of data.accounts) {
			console.log("account", account);
			let acctId = await api.createAccount(account);
			console.log("account id", acctId);
			/*
			await api.addTransactions(
				acctId,
				data.transactions
				.filter(t => t.acctId === acctId)
				.map(convertTransaction),
			);
			*/
		}
//	}

//	await api.runImport('My-Budget', run);

	await api.shutdown();
})();

@joel-jeremy joel-jeremy added the API Issues with the @actual-app/api package label Oct 5, 2023
@8bitgentleman
Copy link

I had the same issues all described here and the only thing that fixed it was downgrading to node v18.18.2 using nvm

@efess
Copy link

efess commented Dec 3, 2023

I'm having this same issue while initializing the API in actual-simplefin-sync - the db sync _fullSync function calls getClock - but this call is too early because setClock has not been called yet.

I wonder if previous "cannot reproduce" attempts in this thread started with an empty dataDir folder?

I'm running node version v18.14.2 on windows/bash

@efess
Copy link

efess commented Dec 3, 2023

This may not be an issue anymore - actual-simplefin-sync was using version 6.2.1 of the API. Updating this to the latest (6.3.0) and this is not reproducible

@ErnstHaagsman
Copy link

I'm reproducing this issue with the following minimal code:

const api = require("@actual-app/api");
(async () => {
    await api.init({
        // This is the URL of your running server
        serverURL: 'http://localhost:5006',
        // This is the password you use to log into the server
        password: 'hunter2',
    });

    await api.shutdown();
})();

Error:

TypeError: Cannot read properties of undefined (reading 'timestamp')
    at _fullSync (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:42591:98)
    at C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:42503:38
    at C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:43449:38
    at handlers.sync (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:38679:73)
    at runHandler (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:39555:33)
    at Object.send (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:39237:94)
    at Object.shutdown (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\index.js:59:25)
    at C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\minimal.js:10:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[Exception] TypeError: Cannot read properties of undefined (reading 'timestamp')
    at _fullSync (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:42591:98)
    at C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:42503:38
    at C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.api.js:43449:38
    at handlers.sync (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle
                                                                                                           e.api.js:38679:73)
    at runHandler (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.ap
                                                                                                           pi.js:39555:33)
    at Object.send (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\app\bundle.a
                                                                                                           api.js:39237:94)
    at Object.shutdown (C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\node_modules\@actual-app\api\dist\index.js
                                                                                                           s:59:25)
    at C:\Users\Ernst.Haagsman\WebstormProjects\actualimport\minimal.js:10:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Process finished with exit code 0

Both with Node 18.20.3 and Node 20.15.0. Actual API version 6.8.2

@ErnstHaagsman
Copy link

Turns out you need to always run api.downloadBudget in between. That fixed the problem for me.

@tom5491
Copy link

tom5491 commented Aug 18, 2024

Not sure if this helps anyone but I was getting the Segmentation fault (core dumped) error and entering npm rebuild fixed it for me

@eddiegroves
Copy link

Confirmed ErnstHaagsman comment above that the work around is to use downloadBudget after init before using other APIs methods.

@youngcw youngcw closed this as completed Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Issues with the @actual-app/api package bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants