You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@texera.apache.org by "aglinxinyuan (via GitHub)" <gi...@apache.org> on 2026/09/24 04:03:52 UTC
[I] @EncodableStringAnnotation on a trait val is silently ignored by pyb [texera]
aglinxinyuan opened a new issue, #8659:
URL: https://github.com/apache/texera/issues/8659
### What happened?
`EncodableInspector.safeAccessed` hops from an accessor to the field it accesses, because that is where a class `val` keeps its annotations. A trait `val` or `var` has no backing field, so the hop lands on `NoSymbol` and drops the marker: with no field to carry them, a trait member's annotations stay on its accessor, whatever their `@Target`. The argument is then classified as a plain literal:
```
trait Labels { @EncodableStringAnnotation val title: String; def snippet = pyb"print($title)" } // title = "hello"
Before: PyLiteralStringRenderer -> print(hello)
After: EncodableStringRenderer -> print(self.decode_python_template('aGVsbG8='))
```
It fails open. There is no compile error and no runtime check: `BoundaryValidator.validateCompileTime` only runs for arguments the inspector classified Encodable, so an unsafe splice of the same value goes uncaught too. The same member as a concrete `val` on a class is encoded correctly.
Nothing in production declares a marked trait member today — the only modifier-position use of the marker outside `pybuilder` is `Attribute.getName()`, a Java method rather than an accessor — so this is latent, but it is the direction that puts a UI-supplied string into generated Python unencoded. The same `safeAccessed` is on `release/v1.2` and `release/v1.3`. First noted while covering the inspector in #7862.
An abstract class's abstract `val` is a different shape: there scalac keeps the marker on neither the accessor nor a field, so the macro cannot see it at all, and the type-position form (`val title: String @EncodableStringAnnotation`, which the `EncodableString` alias expands to) is the one that works.
### How to reproduce?
`pyb` expands to a `private[amber]` factory, so the source has to live under `org.apache.texera.amber`:
```scala
package org.apache.texera.amber.repro
import org.apache.texera.amber.pybuilder.{EncodableStringAnnotation, PythonTemplateBuilder}
import org.apache.texera.amber.pybuilder.PythonTemplateBuilder._
trait Labels {
@EncodableStringAnnotation val title: String
def snippet: PythonTemplateBuilder = pyb"print($title)"
}
object Repro extends App {
val labels = new Labels { val title = "hello" }
println(labels.snippet.encode) // print(hello)
println(labels.snippet.containsEncodableString) // false
}
```
With `class Labels { @EncodableStringAnnotation val title: String = "hello"; ... }` instead, the same two lines print `print(self.decode_python_template('aGVsbG8='))` and `true`.
### Version/Branch
1.4.0-incubating-SNAPSHOT (main)
### Commit Hash (Optional)
8dbf049bd814fde00c0ce1407a1f31c7de03c645
### What browsers are you seeing the problem on?
_No response_
### Relevant log output
_No response_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org