Commit graph

87 commits

Author SHA1 Message Date
Gavin D'souza
71b5c77e6e Merge branch 'develop' of github.com:frappe/frappe into mariadb-client-refactor 2022-07-05 14:55:02 +05:30
Ankush Menat
261fbfcd11
Revert "fix(doc)!: Always cast datetime, date and time fields"
Revert "fix(doc)!: Always cast datetime, date and time fields (#15891)"

This reverts commit d7789ab6ff.
2022-07-05 13:43:32 +05:30
Himanshu
d7789ab6ff
fix(doc)!: Always cast datetime, date and time fields (#15891)
### BREAKING CHANGE
#### Datetime, Date and Time fields will always be cast to respective objects in `setattr`, this will ensure uniformity while accessing the values, no more `getdate`, `get_datetime`, `to_timedelta` wrapper.
- While importing data, the framework does check for `set_only_once`.
- In normal case scenarios, this will work flawlessly since most date fields might not be set_only_once.
- But in Subscription, the date field is set to `set_only_once` and in `after_insert`, `document.save` is called, and while doing so, `set_only_once` is checked [here](1944a547f9/frappe/model/document.py (L566)).
-This works fine if the data imported is in the correct format.
- If the date's data is not in the correct format, the framework throws an error.
- for eg `06-02-2022 00:00:00 != 06-02-2022`
- fixes [Issue/#15370](https://github.com/frappe/frappe/issues/15370)

> no-docs
2022-07-05 07:07:16 +00:00
Ankush Menat
81b37cb7d2
refactor: clean up code to py310 supported features (#17367)
refactor: clean up code to py39+ supported syntax

- f-strings instead of format
- latest typing support instead of pre 3.9 TitleCase
- remove UTF-8 declarations.
- many more changes

Powered by https://github.com/asottile/pyupgrade/ + manual cleanups
2022-07-01 11:51:05 +05:30
gavin
574f160d3c
Merge branch 'develop' into mariadb-client-refactor 2022-06-23 16:13:03 +05:30
Gavin D'souza
1f1d91a056 fix: Make postgres' last_query lazy decodable 2022-06-18 14:04:38 +05:30
phot0n
f6c1eb10dd refactor(minor): modify_values
* don't truncate float(s)
2022-06-18 10:11:58 +05:30
phot0n
2ce6597a69 fix: cast list to tuple when sending parameterized query for postgres 2022-06-17 18:47:06 +05:30
Gavin D'souza
3af8d5caea fix: Add fallbacks for values
Psycopg seems to like None over () and MariaDB - PyMySQL can't seem to
agree on anything - so this seems to keep everyone happy...a very
delicate balance :crie:
2022-06-17 12:47:44 +05:30
Gavin D'souza
90c716bce0 fix(sequence): Setup & use SequenceGeneratorLimitExceeded error 2022-06-17 12:10:43 +05:30
Gavin D'souza
effa942f4c refactor: frappe.db.log_query
* Mogrify queries and set them as frappe.db.last_query instead of
  directly interfacing with the clients
* This is required for now as the MariaDB client uses binary protocol to
  talk to the server and doesn't build the queries itself
* Add typing hints
* Imported Query object as FilterEngine - Query is too ambiguous lol

ref: https://jira.mariadb.org/browse/CONPY-208?focusedCommentId=226873&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-226873
2022-06-16 13:28:54 +05:30
Gavin D'souza
b4578dc632 Merge branch 'develop' of github.com:frappe/frappe into mariadb-client-refactor 2022-06-15 16:40:29 +05:30
Gavin D'souza
b696fa6da5 perf: Pre-compile and re-use regexp pattern
Converted all possible usages of re.* that weren't compiling the regex
separately and re-using it. Separated out the compiled patterns as
global variables. Repetitive patterns could be made DRY-er.

Would be nicer to have all regexes in a single module so that we could
re-use better, keep track of outdated, and keep checks for possible
reDos' etc
2022-06-08 14:07:38 +05:30
gavin
8ffdc2d465 refactor(minor): PostgresDatabase's exceptions
Focus on Non-blocking Postgres exception checking by:

* Use safe getattr to fetch pgcode instead
* Use psycopg errorcodes module to use named variables instead of direct
  codes...for way superior readability xD

Also, moved exceptions out of the main class - just code separation, no
namespace change.
2022-05-25 14:09:31 +05:30
gavin
aaef732581 fix!: Remove frappe.db.create_help_table
Help table has been deprecated for a while. It's safe to get rid of the
API too.
2022-05-24 19:19:53 +05:30
gavin
a17c978065 refactor!: frappe.db.get_database_list
* Drop mandatory unused arg in method call
* Use pluck instead of list comprehension + subscripting
2022-05-24 19:19:53 +05:30
phot0n
f6dac70033 refactor(minor): convert change_name_type_and_make_sequence function to setup_autoincrement_and_sequence method
* chore(Customize Form): remove autoincrement naming option from autoname description

* chore: move sequence cache comment from schema.py to database.py

* chore: added docstrings to some functions
2022-05-13 00:03:19 +05:30
phot0n
cfc905b567 fix: use cast when chaninging name type from varchar to bigint in postgres 2022-05-05 21:31:13 +05:30
phot0n
9f0c40dbba fix: create sequence onchange from any other autoname whcih is not autoincrement
* chore: use class variable for determining sequence cache

* chore: use sql_ddl when creating sequence
2022-05-05 21:31:13 +05:30
Ritwik Puri
b41379c78b
fix: misc fixes (integer primary keys) (#16307)
* fix: misc fixes

local.x gets resetted on every request so switched to a simple dict

simplified is_val_used in set_next_val function for sequences

* chore: use multisql for sequence methods

* fix: fields not updating on form

* minor(base_input): removed unnecessary branching in update_input

* chore: remove prints and rename autoincremented_status_map

* chore: added proper type hint + comment + formatting

* fix: added searching in cast_name rather than handling it manually

* fix: share condition query + test_build_match_conditions

* fix: add cast_name to more places

* test: test for sequence

* fix: sequence functions

* fix: inherit frappetestcase

* minor: attach sequence methods to db context local

* chore: update sequence function names in Database

use frappe.db for sequences in naming.py

* fix: convert filename to str (for autoincremented doctypes)

* chore: better regex for modifying values for postgres

* minor: allow changing name column type (if no data is present in the doctype)

* refactor: validate_autoname

converted it to a simple function
enabled changing autoincrement autoname from customize form

* fix: use sql_ddl for change_column_type in postgres

* fix: use not null constraint in postgres when changing name type

* fix(test): updated test_autoincremented_doctype_transition with transitioning when no data is present

* fix(test): updated test_cast_name

probably messed up during rebase

* fix(test): used rollback upon error in transaction for postgres

* chore: use frappe.db.x methods for sequences

* minor: use temporary sequences in test

* minor: use generate_hash for sequence naming in sequence tests

* chore: replace sequence imports with frappe.db.x

* chore: move out casting name fields to a separate method

* refactor: cast_name

more explicit cases for casts and added docstring

* fix: added space in test_cast_name

* chore: fix linter

* chore: better naming for can_change_name_column_type

* chore: add comment for autoincremented_site_status_map

* chore: update/add docstrings
2022-04-29 15:06:03 +05:30
Suraj Shetty
6b7fda495b Merge branch 'develop' of https://github.com/frappe/frappe into phone_field_control 2022-04-14 14:19:35 +05:30
Shridhar Patil
39f8267a15
feat: added support for data type json (#16187)
> Please provide enough information so that others can review your pull request:

Added json support for postgres and mariadb



> Explain the **details** for making this change. What existing problem does the pull request solve?
https://github.com/frappe/frappe/projects/4#card-50160428


> Screenshots/GIFs
![json](https://user-images.githubusercontent.com/11792643/156367383-8f8492c2-3817-449d-a2dd-c983eeadbb48.gif)



---

**Previous attempts:** 

https://github.com/frappe/frappe/pull/8128
https://github.com/frappe/frappe/pull/7096


Docs: https://frappeframework.com/docs/v13/user/en/basics/doctypes/fieldtypes#json
2022-04-14 04:21:41 +00:00
Noah Jacob
c2f2fc10e7 Merge branch develop into phone_field_control 2022-04-12 20:40:29 +05:30
Suraj Shetty
c0c5b2ebdd
style: format all python files using black (#16453)
Co-authored-by: Frappe Bot <developers@frappe.io>
2022-04-12 10:59:25 +05:30
Noah Jacob
579d0643c4 Merge branch 'develop' into phone_field_control 2022-03-22 15:05:45 +05:30
phot0n
bebc8058b6 feat: integer primary keys 2022-03-11 23:46:00 +05:30
Gavin D'souza
ad1e180666 feat(db): Alias is_missing_table for consistency in APIs 2022-03-11 14:03:21 +05:30
Sagar Vora
a6d991272e fix: sider warning 2022-03-10 09:38:32 +05:30
Sagar Vora
5d93907a19 fix: improve modify_query regex 2022-03-10 09:28:13 +05:30
Saqib Ansari
8f277a247e Merge branch 'develop' of https://github.com/frappe/frappe into autocomplete-control 2022-02-12 16:27:27 +05:30
Saqib Ansari
bd8ac90286
fix(ux): show report button on too many writes error (#15614)
* feat: log errors on too many writes to ease debugging

* fix(ux): extract and show which app/file/function caused too many writes

* fix: postgres error checking assumes exception is postgres exception

* fix: better default for skipping frames

Typically stack is like: some_app -> your_function -> this function. So last 2 frames need to be skipped.

* fix: postgres error checking assumes exception is postgres exception

* fix: better default for skipping frames

Typically stack is like: some_app -> your_function -> this function. So last 2 frames need to be skipped.

* refactor: show Report button instead of logging

* revert: unnecessary new functionality

* test: assert exact exception

Co-authored-by: Ankush Menat <ankush@frappe.io>
2022-01-31 18:57:32 +05:30
Saqib Ansari
51dcf8fd47 feat: add autocomplete option in custom fields 2022-01-29 19:16:03 +05:30
Suraj Shetty
47393bcb85 style: Fix formatting issues 2022-01-24 09:44:25 +05:30
Suraj Shetty
4d384f308b fix: Unique and Index constraints 2022-01-23 22:57:33 +05:30
Suraj Shetty
b180854766
Merge branch 'develop' into phone_field_control 2022-01-14 20:11:11 +05:30
Noah Jacob
e86378f26f
Merge branch 'develop' into phone_field_control 2022-01-07 13:12:33 +05:30
Noah Jacob
938d12b142 fix: sider 2022-01-07 13:04:06 +05:30
Gavin D'souza
981564e544 Merge branch 'develop' into frappe-postgres-changes 2022-01-07 11:37:28 +05:30
Conor
40ba1ac9ba fix: Postgres Compatibility
* Handle inconsistencies in type handling in DatabaseQuery & Database
  APIs
* Update incompatible queries with frappe.qb notation
* Fixed use cases discovered by failing ERPNext CI tests

fix: db independent syntax for user_type

fix: handle postgres datetime values

feat: add ability to auto commit on db inserts

feat: add ability to escape underscore in postgres

fix: handle missing data in test runner bootstrapping

fix: db independent syntax for queries

fix: refactor to use qb

fix: update cache for language

fix: use pluck in email_queue

Co-authored-by: gavin <gavin18d@gmail.com>

fix: don't auto insert on tests for make_property_setter

fix: remove auto_commit in custom_field insertion

fix: remove auto_commit functionality

fix: review comments

fix: revert link validation

fix: style suggestion for readability

Co-authored-by: gavin <gavin18d@gmail.com>

fix: revert .lower() in link validation

fix: add rollback for setup_wizard

Revert "fix: add rollback for setup_wizard"

This reverts commit 83b3b0913db17718ccd5edae01858cff15603829.

Revert "feat: add ability to escape underscore in postgres"

This reverts commit 8ed9c2aa3306438e94bb813f60e65b416d0b947b.

fix: more concise representation of order fields

Co-authored-by: gavin <gavin18d@gmail.com>
2022-01-07 10:44:57 +05:30
Ankush Menat
80d456ef7e fix: avoid cached results for table_exists during install 2022-01-05 11:54:46 +05:30
Ankush Menat
08464553f3 fix: define check_transaction_status for postgres
To implement repeatable reads it has to respect transactions.
2022-01-04 13:59:22 +05:30
Ankush Menat
43364cf89b fix!: use repeatable read isolation level
RR isolation is default in MariaDB, for sake of consistency use same
isolation level in postgres
2022-01-04 13:59:22 +05:30
Noah Jacob
d08a332a85 feat: Phone Field Control Type 2022-01-04 12:58:36 +05:30
Ankush Menat
d603aaf601 fix: define is_syntax_error for postgres 2022-01-04 11:25:08 +05:30
Ankush Menat
600156b1a1 refactor!: allow modified column to be nullable
* updated change_column_type to allow making columns nullable.
* breaking change: in postgres the method was previously nullable by
  default, changed it to be consistent with mariadb.
2021-12-24 16:31:06 +05:30
Diksha Jadhav
c477398a2f feat: make rating field's stars customizable with options field 2021-12-13 16:03:21 +05:30
leela
a76445bcf5 fix: use decimal digits precision 9 instead of 6 while creating schema
Currently we use DECIMAL(18, 6) datatype for float, currency and
percent. But in the system settings we provide a configuration to change the
precision up to 9 digits. This obviously does not work because we do not
store 9 digit precision in database. Fixed by changing the decimal
datatype scale.
2021-09-22 16:07:06 +05:30
gavin
4041442e6a
Merge pull request #13955 from gavindsouza/trim-db
feat: Site Maintenance commands
2021-09-15 17:08:40 +05:30
Gavin D'souza
3adc459e4d Merge branch 'develop' of github.com:frappe/frappe into trim-db 2021-09-14 21:53:21 +05:30
Gavin D'souza
1545ad65d1 fix: Don't need postgres to use Frappe
* Made code DRY-er by using obscure frappe.db.is_data_too_long
* Python would run psycopg import line which would check if postgres is
  installed. Sites just wanting to chill w MariaDB would also need
  Postgres to be installed to get Frappe running. Fixes https://github.com/frappe/frappe/issues/14193
2021-09-14 13:06:59 +05:30