fsanyoto commited on
Commit
f0aa5e9
Β·
verified Β·
1 Parent(s): 0c7b86d

Deploy AIOS web (React glide grid + FastAPI slice)

Browse files
Files changed (1) hide show
  1. royalimports_os/aios_grid.py +40 -5
royalimports_os/aios_grid.py CHANGED
@@ -221,10 +221,38 @@ def _clean_permissions(raw):
221
  return None
222
 
223
 
224
- _FORMULA_CHARS = re.compile(r"^[\w\s{}()+\-*/.,<>=!]*$")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  _FORMULA_REF = re.compile(r"\{([^{}]*)\}")
226
 
227
 
 
 
 
 
 
 
 
 
 
 
 
228
  def _clean_formula(raw, valid_keys=None):
229
  """STRUCTURAL passthrough for a formula field's expression (wave-5 item 9).
230
 
@@ -232,10 +260,15 @@ def _clean_formula(raw, valid_keys=None):
232
  refs, ABS/ROUND/MIN/MAX/IF), and any evaluation error degrades to a BLANK cell β€” never a
233
  wrong number. That is the `_clean_window` split one stratum up, and deliberately NOT a
234
  Python mirror of the grammar: a second engine is the filter_sql-class drift risk.
235
- Structure IS checked β€” charset, length, balanced parens, well-formed non-empty `{refs}` β€”
236
- and at WRITE time (`valid_keys` given) every ref must name a field this table has, fail
237
- closed. At READ time refs are left alone: a referenced field deleted later must blank the
238
- CELLS, not vaporise the column.
 
 
 
 
 
239
  """
240
  if not isinstance(raw, str):
241
  return None
@@ -252,6 +285,8 @@ def _clean_formula(raw, valid_keys=None):
252
  return None
253
  if depth:
254
  return None
 
 
255
  refs = _FORMULA_REF.findall(s)
256
  leftover = _FORMULA_REF.sub("", s)
257
  if "{" in leftover or "}" in leftover: # unbalanced / nested braces
 
221
  return None
222
 
223
 
224
+ #: β›” THE CHARSET MUST ADMIT EVERY TOKEN THE CLIENT ENGINE PARSES, or a legal formula is
225
+ #: refused by a wall that is supposed to be structural (2026-08-03).
226
+ #:
227
+ #: This regex was written when a formula was arithmetic over refs. On 2026-07-31 the client
228
+ #: engine (owner item 2) gained STRING literals, `&` concatenation and `^` β€” CONCATENATE, TEXT,
229
+ #: LEFT/RIGHT/MID, and any `IF(cond, "yes", "no")`. This list was never widened to match, so
230
+ #: every such formula died here: `field_upsert` refused the create, and `fields_from_workspace`
231
+ #: dropped the column on read. Nothing went red β€” a refused create looks like a quiet failure
232
+ #: and a dropped column looks like a column nobody made.
233
+ #:
234
+ #: Found by trying to ship the owner's own Buy signal formula, which is `IF(..., "Buy now",
235
+ #: "OK")` and could not be created through the product UI at all.
236
+ #:
237
+ #: ⚠ IT IS STILL STRUCTURAL, and deliberately not a second grammar β€” that is the filter_sql-class
238
+ #: drift risk this file's docstring names. The charset says which characters may appear; the
239
+ #: engine says what they mean. `_quotes_balanced` below is the one structural rule the quote
240
+ #: character brings with it.
241
+ _FORMULA_CHARS = re.compile(r"^[\w\s{}()+\-*/.,<>=!^&\"]*$")
242
  _FORMULA_REF = re.compile(r"\{([^{}]*)\}")
243
 
244
 
245
+ def _quotes_balanced(s):
246
+ """An even number of `"` β€” the structural half of string support.
247
+
248
+ Sound because the engine's own escape is Excel's: `""` inside a string is one quote, and it
249
+ contributes TWO characters. So a well-formed expression always has an even count and an
250
+ unterminated string always has an odd one. What a balanced pair MEANS is the engine's
251
+ business, exactly as with parentheses.
252
+ """
253
+ return s.count('"') % 2 == 0
254
+
255
+
256
  def _clean_formula(raw, valid_keys=None):
257
  """STRUCTURAL passthrough for a formula field's expression (wave-5 item 9).
258
 
 
260
  refs, ABS/ROUND/MIN/MAX/IF), and any evaluation error degrades to a BLANK cell β€” never a
261
  wrong number. That is the `_clean_window` split one stratum up, and deliberately NOT a
262
  Python mirror of the grammar: a second engine is the filter_sql-class drift risk.
263
+ Structure IS checked β€” charset, length, balanced parens, BALANCED QUOTES, well-formed
264
+ non-empty `{refs}` β€” and at WRITE time (`valid_keys` given) every ref must name a field this
265
+ table has, fail closed. At READ time refs are left alone: a referenced field deleted later
266
+ must blank the CELLS, not vaporise the column.
267
+
268
+ ⚠ A `{ref}` INSIDE A STRING LITERAL is still checked against `valid_keys` at write time, so
269
+ `IF(x, "see {notafield}", "")` is refused. That is a false rejection and it is the
270
+ fail-closed direction: the alternative is teaching this function where strings begin and
271
+ end, which is the second grammar the paragraph above refuses to write.
272
  """
273
  if not isinstance(raw, str):
274
  return None
 
285
  return None
286
  if depth:
287
  return None
288
+ if not _quotes_balanced(s):
289
+ return None
290
  refs = _FORMULA_REF.findall(s)
291
  leftover = _FORMULA_REF.sub("", s)
292
  if "{" in leftover or "}" in leftover: # unbalanced / nested braces