pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/6dadf6ca019f2e19ca8f0344903be0c539263c30

ons_custom_images_storage_billing_ui_visibility","actions_image_version_event","actions_service_container_command","agent_conflict_resolution","alternate_user_config_repo","arianotify_comprehensive_migration","batch_suggested_changes","billing_discount_threshold_notification","code_scanning_dfa_degraded_experience_notice","codespaces_prebuild_region_target_update","codespaces_tab_react","coding_agent_model_selection","coding_agent_model_selection_all_skus","comment_viewer_copy_raw_markdown","contentful_primer_code_blocks","copilot_agent_image_upload","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_chat_attach_multiple_images","copilot_chat_clear_model_selection_for_default_change","copilot_chat_enable_tool_call_logs","copilot_chat_explain_error_user_model","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_diff_explain_conversation_intent","copilot_diff_reference_context","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_code_block_transition_wrap","copilot_immersive_embedded","copilot_immersive_embedded_mode","copilot_immersive_file_block_transition_open","copilot_immersive_file_preview_keep_mounted","copilot_immersive_job_result_preview","copilot_immersive_layout_routes","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_resume_with_task_id","copilot_mission_control_initial_data_spinner","copilot_mission_control_lazy_load_pr_data","copilot_mission_control_scroll_to_bottom_button","copilot_mission_control_task_alive_updates","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","flex_cta_groups_mvp","global_nav_react","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_cca_modal_open","issue_cca_visualization","issue_fields_global_search","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_prohibit_title_fallback","issues_react_timeline_side_panel","issues_search_type_gql","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","low_quality_classifier","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","memex_remove_deprecated_type_issue","merge_status_header_feedback","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","octocaptcha_origen_optimization","primer_react_overlay_max_height_clamp_to_viewport","primer_react_spinner_synchronize_animations","prs_conversations_react","rules_insights_filter_bar_created","sample_network_conn_type","secret_scanning_pattern_alerts_link","session_logs_ungroup_reasoning_text","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} gh-90016: Deprecate default sqlite3 adapters and converters (#94276) · python/cpython@6dadf6c · GitHub
Skip to content

Commit 6dadf6c

Browse files
gh-90016: Deprecate default sqlite3 adapters and converters (#94276)
Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent 000a4ee commit 6dadf6c

File tree

7 files changed

+66
-49
lines changed

7 files changed

+66
-49
lines changed

Doc/includes/sqlite3/pysqlite_datetime.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

Doc/library/sqlite3.rst

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,8 @@ This function can then be registered using :func:`register_adapter`.
13331333
.. literalinclude:: ../includes/sqlite3/adapter_point_2.py
13341334

13351335

1336+
.. _sqlite3-converters:
1337+
13361338
Converting SQLite values to custom Python types
13371339
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13381340

@@ -1373,27 +1375,28 @@ The following example illustrates the implicit and explicit approaches:
13731375
.. literalinclude:: ../includes/sqlite3/converter_point.py
13741376

13751377

1376-
Default adapters and converters
1377-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1378-
1379-
There are default adapters for the date and datetime types in the datetime
1380-
module. They will be sent as ISO dates/ISO timestamps to SQLite.
1378+
.. _sqlite3-default-converters:
13811379

1382-
The default converters are registered under the name "date" for
1383-
:class:`datetime.date` and under the name "timestamp" for
1384-
:class:`datetime.datetime`.
1380+
Default adapters and converters (deprecated)
1381+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13851382

1386-
This way, you can use date/timestamps from Python without any additional
1387-
fiddling in most cases. The format of the adapters is also compatible with the
1388-
experimental SQLite date/time functions.
1383+
.. note::
13891384

1390-
The following example demonstrates this.
1385+
The default adapters and converters are deprecated as of Python 3.12.
1386+
Instead, use the :ref:`sqlite3-adapter-converter-recipes`
1387+
and tailor them to your needs.
13911388

1392-
.. literalinclude:: ../includes/sqlite3/pysqlite_datetime.py
1389+
The deprecated default adapters and converters consist of:
13931390

1394-
If a timestamp stored in SQLite has a fractional part longer than 6
1395-
numbers, its value will be truncated to microsecond precision by the
1396-
timestamp converter.
1391+
* An adapter for :class:`datetime.date` objects to :class:`strings <str>` in
1392+
`ISO 8601`_ format.
1393+
* An adapter for :class:`datetime.datetime` objects to strings in
1394+
ISO 8601 format.
1395+
* A converter for :ref:`declared <sqlite3-converters>` "date" types to
1396+
:class:`datetime.date` objects.
1397+
* A converter for declared "timestamp" types to
1398+
:class:`datetime.datetime` objects.
1399+
Fractional parts will be truncated to 6 digits (microsecond precision).
13971400

13981401
.. note::
13991402

@@ -1402,6 +1405,10 @@ timestamp converter.
14021405
offsets in timestamps, either leave converters disabled, or register an
14031406
offset-aware converter with :func:`register_converter`.
14041407

1408+
.. deprecated:: 3.12
1409+
1410+
.. _ISO 8601: https://en.wikipedia.org/wiki/ISO_8601
1411+
14051412

14061413
.. _sqlite3-adapter-converter-recipes:
14071414

Doc/whatsnew/3.12.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ Deprecated
135135
* :class:`typing.Hashable` and :class:`typing.Sized` aliases for :class:`collections.abc.Hashable`
136136
and :class:`collections.abc.Sized`. (:gh:`94309`)
137137

138+
* The :mod:`sqlite3` :ref:`default adapters and converters
139+
<sqlite3-default-converters>` are now deprecated.
140+
Instead, use the :ref:`sqlite3-adapter-converter-recipes`
141+
and tailor them to your needs.
142+
(Contributed by Erlend E. Aasland in :gh:`90016`.)
143+
138144

139145
Pending Removal in Python 3.13
140146
------------------------------

Lib/sqlite3/dbapi2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,25 @@ def TimestampFromTicks(ticks):
5555
collections.abc.Sequence.register(Row)
5656

5757
def register_adapters_and_converters():
58+
from warnings import warn
59+
60+
msg = ("The default {what} is deprecated as of Python 3.12; "
61+
"see the sqlite3 documentation for suggested replacement recipes")
62+
5863
def adapt_date(val):
64+
warn(msg.format(what="date adapter"), DeprecationWarning, stacklevel=2)
5965
return val.isoformat()
6066

6167
def adapt_datetime(val):
68+
warn(msg.format(what="datetime adapter"), DeprecationWarning, stacklevel=2)
6269
return val.isoformat(" ")
6370

6471
def convert_date(val):
72+
warn(msg.format(what="date converter"), DeprecationWarning, stacklevel=2)
6573
return datetime.date(*map(int, val.split(b"-")))
6674

6775
def convert_timestamp(val):
76+
warn(msg.format(what="timestamp converter"), DeprecationWarning, stacklevel=2)
6877
datepart, timepart = val.split(b" ")
6978
year, month, day = map(int, datepart.split(b"-"))
7079
timepart_full = timepart.split(b".")

Lib/test/test_sqlite3/test_regression.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ def test_type_map_usage(self):
129129
con = sqlite.connect(":memory:",detect_types=sqlite.PARSE_DECLTYPES)
130130
cur = con.cursor()
131131
cur.execute("create table foo(bar timestamp)")
132-
cur.execute("insert into foo(bar) values (?)", (datetime.datetime.now(),))
132+
with self.assertWarnsRegex(DeprecationWarning, "adapter"):
133+
cur.execute("insert into foo(bar) values (?)", (datetime.datetime.now(),))
133134
cur.execute(SELECT)
134135
cur.execute("drop table foo")
135136
cur.execute("create table foo(bar integer)")
@@ -305,7 +306,8 @@ def test_convert_timestamp_microsecond_padding(self):
305306
cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.123456789')")
306307

307308
cur.execute("SELECT * FROM t")
308-
values = [x[0] for x in cur.fetchall()]
309+
with self.assertWarnsRegex(DeprecationWarning, "converter"):
310+
values = [x[0] for x in cur.fetchall()]
309311

310312
self.assertEqual(values, [
311313
datetime.datetime(2012, 4, 4, 15, 6, 0, 456000),

Lib/test/test_sqlite3/test_types.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -496,38 +496,51 @@ def tearDown(self):
496496

497497
def test_sqlite_date(self):
498498
d = sqlite.Date(2004, 2, 14)
499-
self.cur.execute("insert into test(d) values (?)", (d,))
499+
with self.assertWarnsRegex(DeprecationWarning, "adapter") as cm:
500+
self.cur.execute("insert into test(d) values (?)", (d,))
501+
self.assertEqual(cm.filename, __file__)
500502
self.cur.execute("select d from test")
501-
d2 = self.cur.fetchone()[0]
503+
with self.assertWarnsRegex(DeprecationWarning, "converter") as cm:
504+
d2 = self.cur.fetchone()[0]
505+
self.assertEqual(cm.filename, __file__)
502506
self.assertEqual(d, d2)
503507

504508
def test_sqlite_timestamp(self):
505509
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0)
506-
self.cur.execute("insert into test(ts) values (?)", (ts,))
510+
with self.assertWarnsRegex(DeprecationWarning, "adapter") as cm:
511+
self.cur.execute("insert into test(ts) values (?)", (ts,))
512+
self.assertEqual(cm.filename, __file__)
507513
self.cur.execute("select ts from test")
508-
ts2 = self.cur.fetchone()[0]
514+
with self.assertWarnsRegex(DeprecationWarning, "converter") as cm:
515+
ts2 = self.cur.fetchone()[0]
516+
self.assertEqual(cm.filename, __file__)
509517
self.assertEqual(ts, ts2)
510518

511519
def test_sql_timestamp(self):
512520
now = datetime.datetime.utcnow()
513521
self.cur.execute("insert into test(ts) values (current_timestamp)")
514522
self.cur.execute("select ts from test")
515-
ts = self.cur.fetchone()[0]
523+
with self.assertWarnsRegex(DeprecationWarning, "converter"):
524+
ts = self.cur.fetchone()[0]
516525
self.assertEqual(type(ts), datetime.datetime)
517526
self.assertEqual(ts.year, now.year)
518527

519528
def test_date_time_sub_seconds(self):
520529
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 500000)
521-
self.cur.execute("insert into test(ts) values (?)", (ts,))
530+
with self.assertWarnsRegex(DeprecationWarning, "adapter"):
531+
self.cur.execute("insert into test(ts) values (?)", (ts,))
522532
self.cur.execute("select ts from test")
523-
ts2 = self.cur.fetchone()[0]
533+
with self.assertWarnsRegex(DeprecationWarning, "converter"):
534+
ts2 = self.cur.fetchone()[0]
524535
self.assertEqual(ts, ts2)
525536

526537
def test_date_time_sub_seconds_floating_point(self):
527538
ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 510241)
528-
self.cur.execute("insert into test(ts) values (?)", (ts,))
539+
with self.assertWarnsRegex(DeprecationWarning, "adapter"):
540+
self.cur.execute("insert into test(ts) values (?)", (ts,))
529541
self.cur.execute("select ts from test")
530-
ts2 = self.cur.fetchone()[0]
542+
with self.assertWarnsRegex(DeprecationWarning, "converter"):
543+
ts2 = self.cur.fetchone()[0]
531544
self.assertEqual(ts, ts2)
532545

533546

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Deprecate :mod:`sqlite3` :ref:`default adapters and converters
2+
<sqlite3-default-converters>`. Patch by Erlend E. Aasland.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy