The headline came catchy, but boiling. I must say that it will be about 1C. Dear 1C-nicks, you do not know how to work with transactions and do not understand what exceptions are. I came to this conclusion by looking at a large amount of code on 1C, born in the wilds of a domestic enterprise. In typical configurations, this is pretty good, but the horrendous amount of custom code is written incompetently in terms of working with the database. Have you ever seen the error "There have already been errors in this transaction"? If so, then the title of the article applies to you. Let's see under the cut, finally, what are transactions and how to handle them correctly, working with 1C.
To begin with, let's see what the error is "In this transaction, errors have already occurred." This is, in fact, a very simple thing: you are trying to work with a database inside an already rolled back (canceled) transaction. For example, the CancelTransaction method was called somewhere, and you are trying to commit it.
Why is that bad? Because this error tells you nothing about where the problem actually happened. When a user receives a screenshot with such text, and especially for server code that the person does not work with interactively, this ... I wanted to write a "critical error", but I thought it was a buzzword that nobody already pays attention to .... This is ass. This is a programming error. This is not a random crash. This cant, which must be redone immediately. Because when your server’s background processes get up at night and the company starts to lose money fast, then “There have already been errors in this transaction” is the last thing you want to see in the diagnostic logs.
There is, of course, the possibility that the server’s technological log (it’s included in production, right?) Will somehow help diagnose the problem, but I can’t think of an option right now - how to find the real cause of this error in it. And the real reason is one - programmer Vasya received an exception inside the transaction and decided that once - not a carabas "think, mistake, let's go further."
It is embarrassing to write about truism, but, probably, it is necessary a little. Transactions in 1C are the same as transactions in a DBMS. These are not some special "1C-s" transactions, they are transactions in a DBMS. According to the general idea of ​​transactions, they can either be executed entirely or not executed at all. All changes to database tables made within a transaction can be undone at once, as if nothing had happened.
Further, you need to understand that nested transactions are not supported in 1C. In fact, they are not supported not "in 1C", but are not supported at all. At least, those DBMS with which 1C can work. Nested transactions, for example, are not in MS SQL and Postgres. Each "nested" call to Start Transaction simply increases the transaction counter, and each call to "Commit Transaction" reduces this counter. This behavior is described in many books and articles, but the conclusions from this behavior are apparently not well understood. Strictly speaking, in SQL there is a so-called. SAVEPOINT, but 1C does not use them, and the thing is quite specific.
Hereinafter, especially for the Warriors of the True Faith, who believe that the code should be written only in English, an analogue of the code in English syntax 1C will be given under the spoilers.
()
();
= .();
. = " ";
.();
;
();
, . , .
, ? . , . ? , . — . — deadlock, , , , . : deadlock .
, . 1- . , , 3 . , , 1 :)
, . 1 , "" "". , , :). , . , IT- .
, , ( ), . " ". , , . , . , , , ELK- 1 … (, , , :))
, , . , , ".()". ( ) , .
, .
, (, "()") . "" , , - -, . , : , , .
. 1 SonarQube . , 1, , …
? 90% . , 1 . , 1, .
:
()
= ();
();
, . - , . — - . — … , ? "" , . , . , , , " -…"
"-" : . . , , , - , . .
:
()
= ();
();
();
// , .
— . , ( — ) , . -, , .
, 3- . — .
. , , , .
1 , . , . , :
()
();
= .();
. = " ";
.();
.(" %1", );
;
;
;
();
, , ? , . . — , , " ", . , .
, 1- , , . , . "()" 1 , . 1 (, -), "" . , " ".
, , , - "" . , - . , , .
, , . . .
, 1 . :
3 , . — , .
. ( ) , . , , .
? : : , , .
? :
();
();
();
, — . - , "" . , :
();
();
// ?
;
();
, , ? ? , , . ? ? , . "" . - throw.
();
();
;
;
();
, … , ? : .
();
();
();
;
;
();
, , . , , (). , ? , , ? , , . , , . - .
, , "-" . :
**UPD: , . , -.
();
();
();
()
();
;
;
;
, "" . "" ""? , : , , . , . . . , . . . "" . , , , "" .
, .
:
();
();
();
"" , .
:
()
()
. , . . , . . .
:
()
()
: — . ? , - ? .
:
()
.()
//
//
;
();
:
()
.()
.();
(" ");
;
;
();
. . , . .
, , , , , 1 . , , , Highload, , . ORM, GUI, -, Reporting, . , , — 1, — . , , , , , -, . 1 . 20 / -. , , . - 1 , , . - "()"....
— , . 1 - . , . " 1" — . .
Source: https://habr.com/ru/post/419715/
All Articles