Skip to content

ORM : The required field database is null, v panic #24220

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

Closed
Avey777 opened this issue Apr 15, 2025 · 1 comment
Closed

ORM : The required field database is null, v panic #24220

Avey777 opened this issue Apr 15, 2025 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@Avey777
Copy link

Avey777 commented Apr 15, 2025

Describe the bug

The required field database is null, v panic

Reproduction Steps

Image

module main

import db.mysql
import time
import orm

fn db_mysql() !mysql.DB {
	mut mysql_config := mysql.Config{
		host:     'mysql2.sqlpub.com'
		port:     3307
		username: 'vcore_test'
		password: 'wfo8wS7CylT0qIMg'
		dbname:   'vcore_test'
	}
	mut conn := mysql.connect(mysql_config) or { return err }
	return conn
}

@[table: 'sys_users']
struct User {
pub:
	id         string     @[immutable; primary; sql: 'id'; sql_type: 'VARCHAR(255)'; unique]
	name       string     @[immutable; sql: 'username'; sql_type: 'VARCHAR(255)'; unique]
	created_at ?time.Time @[omitempty; sql_type: 'TIMESTAMP']
	updated_at time.Time  @[default: '0001-01-01T00:00:00 +00:00'; omitempty; sql_type: 'TIMESTAMP']
}

fn main() {
	mut db := db_mysql() or { panic('failed to connect to database') }
	defer { db.close() }

	mut result := sql db {
		select from User
	} or { panic(err) }
	dump(result)

	mut qb := orm.new_query[User](db)
	result1 := qb.select('id', 'username')!.query()!
	dump(result1)
}

Expected Behavior

success

Current Behavior

V panic: as cast: cannot cast orm.Null to string
v hash: 3b4c016
/tmp/v_1000/orm.01JRVGQJH83TA5PGMBGH7MTE7A.tmp.c:6880: at _v_panic: Backtrace
/tmp/v_1000/orm.01JRVGQJH83TA5PGMBGH7MTE7A.tmp.c:7272: by __as_cast
/tmp/v_1000/orm.01JRVGQJH83TA5PGMBGH7MTE7A.tmp.c:11887: by orm__QueryBuilder_T_main__User_map_row_T_main__User
/tmp/v_1000/orm.01JRVGQJH83TA5PGMBGH7MTE7A.tmp.c:12161: by orm__QueryBuilder_T_main__User_query_T_main__User
/tmp/v_1000/orm.01JRVGQJH83TA5PGMBGH7MTE7A.tmp.c:14849: by main__main
/tmp/v_1000/orm.01JRVGQJH83TA5PGMBGH7MTE7A.tmp.c:14987: by main

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.10 3b4c016

Environment details (OS name and version, etc.)

V full version V 0.4.10 86536e4.3b4c016
OS linux, Deepin 23
Processor 6 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
Memory 0.26GB/7.61GB
V executable /home/Jengro/.vmr/versions/v_versions/v_latest/v
V last modified time 2025-04-15 00:10:48
V home dir OK, value: /home/Jengro/.vmr/versions/v_versions/v_latest
VMODULES OK, value: /home/Jengro/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/Jengro/Documents/Dev/v-product/vprod-workspase/example
Git version git version 2.45.2
V git status weekly.2025.14-48-g3b4c0165
.git/config present true
cc version cc (Deepin 12.3.0-17deepin8) 12.3.0
gcc version gcc (Deepin 12.3.0-17deepin8) 12.3.0
clang version Deepin clang version 17.0.6 (5deepin5)
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version N/A
glibc version ldd (Debian GLIBC 2.38-6deepin7) 2.38

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@Avey777 Avey777 added the Bug This tag is applied to issues which reports bugs. label Apr 15, 2025
Copy link

Connected to Huly®: V_0.6-22603

@JalonSolov JalonSolov marked this as a duplicate of #24221 Apr 15, 2025
@huly-for-github huly-for-github bot marked this as not a duplicate of #24221 Apr 15, 2025
@Avey777 Avey777 closed this as completed Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant