datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

Add regex_engine="python-re" if regex uses lookaround

Open camillol opened this issue 9 months ago • 2 comments

Pydantic 2 uses Rust's regex implementation by default, which runs in linear time but doesn't support lookarounds or backreferences. If a field needs to use such a regex, it is necessary to set up the model's config to use Python's regex engine instead. See documentation.

This change adds the necessary config when generating Pydantic 2 models that contain a field with a pattern containing lookarounds.

camillol avatar May 03 '24 03:05 camillol

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Please upload report for BASE (main@fcab9a4). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1945   +/-   ##
=======================================
  Coverage        ?   98.47%           
=======================================
  Files           ?       37           
  Lines           ?     4189           
  Branches        ?      974           
=======================================
  Hits            ?     4125           
  Misses          ?       47           
  Partials        ?       17           
Flag Coverage Δ
unittests 98.13% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar May 03 '24 03:05 codecov[bot]

CodSpeed Performance Report

Merging #1945 will not alter performance

Comparing camillol:regex_engine (cdcd01d) with main (fcab9a4)

Summary

✅ 29 untouched benchmarks

codspeed-hq[bot] avatar May 03 '24 03:05 codspeed-hq[bot]