Title: Variable 'dsn' needs to be initialized in create_database(). Otherwise 'UnboundLocalError: cannot access local variable' possible if 'database' arg. points to an ALIAS · Issue #56 · FirebirdSQL/python3-driver · GitHub
Open Graph Title: Variable 'dsn' needs to be initialized in create_database(). Otherwise 'UnboundLocalError: cannot access local variable' possible if 'database' arg. points to an ALIAS · Issue #56 · FirebirdSQL/python3-driver
X Title: Variable 'dsn' needs to be initialized in create_database(). Otherwise 'UnboundLocalError: cannot access local variable' possible if 'database' arg. points to an ALIAS · Issue #56 · FirebirdSQL/python3-driver
Description: Please consider func create_database(). There is following code starting from line 2400: db_config: DatabaseConfig = driver_config.get_database(database) if db_config is None: db_config = driver_config.db_defaults srv_config = driver_con...
Open Graph Description: Please consider func create_database(). There is following code starting from line 2400: db_config: DatabaseConfig = driver_config.get_database(database) if db_config is None: db_config = driver_co...
X Description: Please consider func create_database(). There is following code starting from line 2400: db_config: DatabaseConfig = driver_config.get_database(database) if db_config is None: db_config = driver_co...
Opengraph URL: https://github.com/FirebirdSQL/python3-driver/issues/56
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Variable 'dsn' needs to be initialized in create_database(). Otherwise 'UnboundLocalError: cannot access local variable' possible if 'database' arg. points to an ALIAS","articleBody":"Please consider func create_database(). \n\nThere is following code starting from line 2400:\n```\n db_config: DatabaseConfig = driver_config.get_database(database)\n if db_config is None:\n db_config = driver_config.db_defaults\n srv_config = driver_config.server_defaults\n if _is_dsn(database):\n dsn = database\n database = None\n srv_config.host.clear()\n else:\n . . .\n```\n\nIf control falls into the branch \"if db_config is None\" and then into \"if _is_dsn(database)\" -- all fine.\nBut if ```_is_dsn(database)``` returns False then we have a problem: ```dsn``` remains undefined until following call at line 2435:\n```\n dsn = _connect_helper(dsn, srv_config.host.value, srv_config.port.value,\n database, db_config.protocol.value)\n```\nThis code will raise \"UnboundLocalError: cannot access local variable 'dsn' where it is not associated with a value\"\n\nFunction ```_is_dsn()``` may return False if value of ```database``` argument represents an ALIAS rather than file (e.g. ```db_main_alias``` used in replication tests or similar strings).\n\n\nThis is what i propose:\n```\nComparing files core.py and core-upd.py\n***** core.py\n 2401: if db_config is None:\n 2402: db_config = driver_config.db_defaults\n***** core-upd.py\n 2402: # pzotov, 11.09.2025: we have to initialize here 'dsn' variable otherwise we get error\n 2403: # UnboundLocalError: cannot access local variable 'dsn' where it is not associated with a value\n 2404: # if the 'database' argument is an ALIAS, e.g. 'db_main_alias' etc!\n 2405: dsn: str | None = None\n 2407: if db_config is None:\n 2408: db_config = driver_config.db_defaults\n*****\n```","author":{"url":"https://github.com/pavel-zotov","@type":"Person","name":"pavel-zotov"},"datePublished":"2025-09-11T16:28:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/56/python3-driver/issues/56"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a9a69da1-637e-e063-92c1-e2c2ff5439b3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8682:199F7E:4717ED8:62FF8F6:69714CBE |
| html-safe-nonce | 393bdc41acc472066f734b1408c8201c121816ad0a12b90d6b77eaf31f34a339 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjgyOjE5OUY3RTo0NzE3RUQ4OjYyRkY4RjY6Njk3MTRDQkUiLCJ2aXNpdG9yX2lkIjoiMjkyMDI4ODEwNjE1OTYyMzM1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 868a4c132955c28ddfff36c705cea37373845a130a324dfe4b5cb95ee815f394 |
| hovercard-subject-tag | issue:3407277622 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/FirebirdSQL/python3-driver/56/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b550e1d7d34a128a751c11bb925ffbf90a4c4928ec6576b0adb0976eb2bd5836/FirebirdSQL/python3-driver/issues/56 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b550e1d7d34a128a751c11bb925ffbf90a4c4928ec6576b0adb0976eb2bd5836/FirebirdSQL/python3-driver/issues/56 |
| og:image:alt | Please consider func create_database(). There is following code starting from line 2400: db_config: DatabaseConfig = driver_config.get_database(database) if db_config is None: db_config = driver_co... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pavel-zotov |
| hostname | github.com |
| expected-hostname | github.com |
| None | da7cbccf7f40bcd9540003423d9bef63b2fe7bb0b73fc59d91b5ae5b46000c90 |
| turbo-cache-control | no-preview |
| go-import | github.com/FirebirdSQL/python3-driver git https://github.com/FirebirdSQL/python3-driver.git |
| octolytics-dimension-user_id | 6057940 |
| octolytics-dimension-user_login | FirebirdSQL |
| octolytics-dimension-repository_id | 260167348 |
| octolytics-dimension-repository_nwo | FirebirdSQL/python3-driver |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 260167348 |
| octolytics-dimension-repository_network_root_nwo | FirebirdSQL/python3-driver |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c9e6c71b091ca750658a3b2e3c82b0b85555f788 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width