Token-generating automation scripts fail in 4.5 (ok in 4.4.10) #21679
Replies: 1 comment
-
|
@bevand10, thanks for the report. I’ve converted this to a discussion because the report appears to point to custom automation rather than a bug in NetBox itself. Please keep in mind that minor NetBox releases may include breaking changes for API consumers and other integrations, so custom automation may need to be updated between releases. In this case, the v4.5.0 release notes call out the changes to I’d also be cautious about managing tokens by writing directly to the ORM from a shell script. For example: if changed:
token_obj.save()Calling If you need to automate token creation, I’d recommend using the REST API. The docs cover both token provisioning and creating tokens for other users, and pynetbox can help with that as well. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
NetBox Edition
NetBox Community
NetBox Version
v4.5.4
Python Version
3.12
Steps to Reproduce
GIVEN
An automation script generates a user token (using the Netbox generator script) and assigns to a user using the NetBox manage.py shell script as follows:
WHEN
When used in a 4.4 series system, the script works well, no errors. The underying database schema at 4.4.10 is:
\d users_token Table "public.users_token" Column | Type | Collation | Nullable | Default ---------------+--------------------------+-----------+----------+---------------------------------- id | bigint | | not null | generated by default as identity created | timestamp with time zone | | not null | expires | timestamp with time zone | | | key | character varying(40) | | not null | write_enabled | boolean | | not null | description | character varying(200) | | not null | user_id | bigint | | not null | allowed_ips | cidr[] | | | last_used | timestamp with time zone | | | Indexes: "users_token_pkey" PRIMARY KEY, btree (id) "users_token_key_820deccd_like" btree (key varchar_pattern_ops) "users_token_key_key" UNIQUE CONSTRAINT, btree (key) "users_token_user_id_af964690" btree (user_id) Foreign-key constraints: "users_token_user_id_af964690_fk_auth_user_id" FOREIGN KEY (user_id) REFERENCES users_user(id) DEFERRABLE INITIALLY DEFERRED Referenced by: TABLE "netbox_proxbox_netboxendpoint" CONSTRAINT "netbox_proxbox_netbo_token_id_db9b4868_fk_users_tok" FOREIGN KEY (token_id) REFERENCES users_token(id) DEFERRABLE INITIALLY DEFERREDHowever, when used in a 4.5.4 system, the script fails as shown below.
The schema for the
users_tokentable has changed between 4.4 and 4.5. It is now:THEN
Given I'm using the netbox models to do this work, is the error mine, or should the token model compensate accordingly?
Expected Behavior
User token successfully applied to the user.
Observed Behavior
These errors emit when running the same script:
Beta Was this translation helpful? Give feedback.
All reactions